0

How to read From XML <returnMsg>Successful</returnMsg> value of this tag in java? How to read the data of the tags in this example. I am getting The processing instruction target matching "[xX][mM][lL]" is not allowed. Exception is getting

     <?xml version="1.0" encoding="utf-8"?>
            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <soapenv:Body>
                    <doServiceResponse xmlns="http://ocs.ztesoft.com">
                        <doServiceReturn>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;zsmart&gt;

  &lt;Data&gt;
    &lt;header&gt;
      &lt;returnMsg&gt;Successful&lt;/returnMsg&gt;
      &lt;ACTION_ID&gt;ModifyBalReturnAllBal&lt;/ACTION_ID&gt;
      &lt;REQUEST_ID&gt;0032013070900000503&lt;/REQUEST_ID&gt;
      &lt;returnCode&gt;0&lt;/returnCode&gt;
    &lt;/header&gt;
    &lt;body&gt;


      &lt;TransactionSN&gt;503&lt;/TransactionSN&gt;
    &lt;/body&gt;
  &lt;/Data&gt;
&lt;/zsmart&gt;
            </doServiceReturn></doServiceResponse></soapenv:Body></soapenv:Envelope>

JAVA CODE

dbf = DocumentBuilderFactory.newInstance();
            db = dbf.newDocumentBuilder();

            is = new InputSource();
            is.setCharacterStream(new StringReader(respString));
            doc = db.parse(is);
            nodes = doc.getElementsByTagName("soapenv:Envelope");
            for (int i = 0; i < nodes.getLength(); i++) {
                Element element = (Element) nodes.item(i);



                NodeList txnStatus = element.getElementsByTagName("returnCode");
                Element line = (Element) txnStatus.item(0);
                bean.setTxnStatus(getCharacterDataFromElement(line));



                NodeList message = element.getElementsByTagName("returnMsg");
                line = (Element) message.item(0);
                bean.setMessage(getCharacterDataFromElement(line));
            }

Exception

org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.
1
  • add your code and error Commented Jul 10, 2013 at 5:31

1 Answer 1

1

There are many way to convert XML file to JAVA OBJECT. SAX and JAXB algorithms are two of them. JAXB algorithm is more easily to use. i prefer to use JAXB. HERE is the link that helps you to create Object from XML file. enjoy it...

http://www.mkyong.com/java/jaxb-hello-world-example/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.