You need to sign in to do that
Don't have an account?
RedSales
XMLStreamReader - How To Get A Specific 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 but I'm still unsure as to what's required.
My SOAP response XMl is similar to the following
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<user_createResponse xmlns="http://dummyValue">
<user_createResult>28</user_createResult>
</user_createResponse>
</soap:Body>
</soap:Envelope>
I tried to use
XmlStreamReader xmlRead = res.getXmlStreamReader();
System.debug('key val = ' + xmlRead.getAttributeValue('', 'user_createResult'));
But I get an error such as "illegal State: Current state is not among the states START_ELEMENT , ATTRIBUTEvalid for getAttributeValue(...."
is it not possible to just name the attribute I want or is it necessary to somehow loop through each element or go to an element number?
Any tips on the above would be welcome.
Thanks!
I suggest you to use Dom.Document and Dom.XMLNode classes.
I have written below class for you. You may use it, as it is or change it per your need.
Hope that helps.
Afzal
All Answers
I suggest you to use Dom.Document and Dom.XMLNode classes.
I have written below class for you. You may use it, as it is or change it per your need.
Hope that helps.
Afzal
Thanks for the help. Much appreciated!
Thanks .It helped a lot.