function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
giribabu gedagiribabu geda 

How to loopthrough an XML string and get the Attribute values

hi all,


    I am writing an apex webservice which reads XNL string from a thirdparty application.


the XMl looks like the Below format


<root    name="test"  place="dc">

 <childone>

<item firstname="value" lastname="value"></item>

<item firstname="value" lastname="value"></item>

</childone>

</root>



tha code i wrote looks as follows:


XMLStreamReader  reader =new XMLStreamreader(str)

reader.setClalescing(true)

try

{

    while(reader.hasNext())

    {

      if(reader.getEventtype()=xmltag.STARTELEMENT() && reader.getLocalName()='root)

        {

           string str1=reader.getAttributeValue(Null,'name');
           string str2=reader.getAttributeValue(Null,'Place');

       }

       if(reader.getEventtype()=xmltag.STARTELEMENT() && reader.getLocalName()='childone')
       {

          reader.nexttag();

          if(reader.getEventtype()=xmltag.STARTELEMENT() && reader.getLocalName()='item')

          {

                here i am trying to get the attribute values of all items.how do i do that.

          }

       }

    }

}