java builder.parse_builder.parse((new StringReader(xml))返回DeferredDocumentImpl

我试图理解我可能犯的错误,但无法找到解决方案 .

public static Document getXMLFromString(String xml) {

org.w3c.dom.Document doc = null;

try {

DocumentBuilderFactory factory = DocumentBuilderFactory

.newInstance();

factory.setNamespaceAware(true);

DocumentBuilder builder;

builder = factory.newDocumentBuilder();

doc = (org.w3c.dom.Document) builder.parse(new InputSource(

new StringReader(xml)));

} catch (SAXException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} catch (ParserConfigurationException e) {

e.printStackTrace();

}

return doc;

}

我做了导入org.w3c.dom.Document

我在这里称这个方法:

private Node getAuthToken(SOAPMessage responseAuth) throws SOAPException,

TransformerException, ParserConfigurationException, IOException,

SAXException {

String s = indentXML(responseAuth.getSOAPPart().getContent());

Document doc = getXMLFromString(s);

NodeList authTokenNodeList = doc.getElementsByTagName("authToken");

return authTokenNodeList.item(0);

}

NodeList为空 .

在网上研究之后,每个人都使用此代码将字符串解析为Document . 我没有任何异常但是在调用方法parse()之后,doc的值被设置为[#document:null] DeferredDocumentImpl .

我正在使用org.w3c.dom中的所有内容 .

xml是包含的字符串

36

...

...

false

36

以下是我在SOAP调用后构建字符串的方法:

String xml = indentXML(responseAuth.getSOAPPart().getContent());

我究竟做错了什么?

这就是我想以一种简单的方式做的事情:

StringBuilder soapResponse = new StringBuilder(...

...

...

);

org.w3c.dom.Document doc = null;

try {

DocumentBuilderFactory factory = DocumentBuilderFactory

.newInstance();

factory.setNamespaceAware(true);

DocumentBuilder builder;

builder = factory.newDocumentBuilder();

doc = (org.w3c.dom.Document) builder.parse(new InputSource(

new StringReader(soapResponse.toString())));

} catch (SAXException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} catch (ParserConfigurationException e) {

e.printStackTrace();

}

NodeList authTokenNodeList = doc.getElementsByTagName("authToken");

Node n = authTokenNodeList.item(0);

String s = n.getNodeValue();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值