my xml string is below -
<articles>
<article>
<source>EN-US</source>
<target>SL</target>
<id>ka1800000000eCYAAY</id>
<publishstatus>Draft</publishstatus>
<fields>
<field name="BU_Type_SMB__c" translate="false">false</field>
<field name="BU_Type__c" translate="false">RBU</field>
<field name="BU_Type_text__c" translate="false">HCP</field>
<field name="Auto_Assignment_Rule_Enabled__c" translate="false">false</field>
</fields>
</article>
I have tried like this -
public void XMLParsingUsingStreamreader(){
string xml = '<articles><article><source>EN-US</source><target>SL</target><id>ka1800000000eCYAAY</id><publishstatus>Draft</publishstatus><fields><field name="BU_Type_SMB__c" translate="false">false</field><field name="BU_Type__c" translate="false">RBU</field><field name="BU_Type_text__c" translate="false">HCP</field><field name="Auto_Assignment_Rule_Enabled__c" translate="false">false</field></fields></article></articles>';
XmlStreamReader xsr = new XmlStreamReader(xml);
//system.debug('-------getLocalname------'+xsr.getLocalName());
while(xsr.hasNext()){
system.debug('---------Event_type-------'+xsr.getEventType());
if(xsr.getEventType() == XmlTag.START_ELEMENT){
system.debug('-------getLocalname------'+xsr.getLocalName());
if('article' == xsr.getLocalName()){
if('source' == xsr.getLocalName()){
if(xsr.getEventType() == XmlTag.END_ELEMENT){
break;
}else if(xsr.getEventType() == XmlTag.CHARACTERS){
//String source = xsr.getText();
system.debug('------source--------'+xsr.getText());
break;
}
}
}
}
xsr.next();
}
}
but I'm not able to get the text inside the tags. Plz help me with that.