Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Java读取XML中的XML_Java_Xml - Fatal编程技术网

使用Java读取XML中的XML

使用Java读取XML中的XML,java,xml,Java,Xml,如何从XML中读取java中此标记的成功值? 如何读取本例中标记的数据。 我获取的处理指令目标不允许与“[xX][mM][lL]”匹配。例外情况越来越严重 <?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http

如何从XML中读取java中此标记的成功值? 如何读取本例中标记的数据。 我获取的处理指令目标不允许与“[xX][mM][lL]”匹配。例外情况越来越严重

     <?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>

有很多方法可以将
XML
文件转换为
JAVA对象
SAX
JAXB
算法是其中的两种。
JAXB
算法更易于使用。我更喜欢使用
JAXB
。 下面是帮助您从
XML
文件创建对象的链接。 享受它


添加您的代码和错误
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));
            }
org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.