问题遇到的现象和发生背景
dom4j解析xml 获取节点的全部路径
结果就是子节点的属性字段名不能跟父的一样
问题相关代码,请勿粘贴截图
<?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>
<hgwTerminalRestartResponse xmlns="http://www.example.org/MobileLoadingMachine/">
<responseStr xmlns=""><?xml version="1.0" encoding="UTF-8"?> <root><resultCode>3</resultCode></root></responseStr>
</hgwTerminalRestartResponse>
</soapenv:Body>
</soapenv:Envelope>
运行结果及报错内容
运行结果:
/soapenv:Envelope
/soapenv:Envelope/soapenv:Body
/soapenv:Envelope/soapenv:Body/[name()='hgwTerminalRestartResponse']
/soapenv:Envelope/soapenv:Body/[name()='hgwTerminalRestartResponse']/responseStr
后面body的有问题
我的解答思路和尝试过的方法
多次尝试:把hgwTerminalRestartResponse xmlns改成xmlns1 和responseStr的xmlns改成xmlns2结果就可以了,为什么会这样
还有就是如果不改这个xmlns的名称怎么解析。
我想要达到的结果
预期达到的效果
/soapenv:Envelope
/soapenv:Envelope/soapenv:Body
/soapenv:Envelope/soapenv:Body/hgwTerminalRestartResponse
/soapenv:Envelope/soapenv:Body/hgwTerminalRestartResponse/responseStr