You need to sign in to do that
Don't have an account?
XMLStreamReader - How To Get A Attribute/Element value!
Hello,
I have an apex class in which i call a web service. I receive a response value from the webservice in which I need to extract a key value from. I've been looking at the XMLStreamReader documentation at http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_xml_XmlStream_reader.htm
My Rest Api Xml response is :
String response=
<xml version='1.0' encoding='UTF-8' ?>
<response><status>listing_ok</status>
<tree><folder id="0" name="" >
<folders>
<folder id="297301978" name="Bicky Rista" ></folder>
<folder id="297301898" name="Jason" ></folder>
<folder id="297301898" name="Box.net" ></folder>
</folders>
</folder>
</tree>
</response>
I am doing this:
XmlStreamReader reader = new XmlStreamReader(response);
// Read through the XML
//and extract the folderid
while(reader.hasNext()) {
// System.debug('Event Type:' + reader.getEventType());
if (reader.getEventType() == XmlTag.START_ELEMENT && reader.getlocalname()=='folder') {
FolderID=reader.getAttributeValue(null,'id');
reader.next();
// System.debug('=================='+reader.getText());
// FolderID= reader.getText();
}
reader.next();
}
Above am getting the id of the Ist folder inside Parent Folder.
As you guys can see Parent Folder has 3 Subfolders.
I want to know to the id of the sub- folder on the basis of the foldername.How can i achieve this.?
Thanks.!
Yes It's easier through XML Dom library.
All Answers
I think it would be easier if you used the DOM class instead. Then you could use the getChildElements method to get the subfolders of each parent folder.
Yes It's easier through XML Dom library.