gpt4 book ai didi

C# XPath Soap,如何导航到嵌入式节点

转载 作者:太空宇宙 更新时间:2023-11-03 14:16:09 24 4
gpt4 key购买 nike

在 C#、Asp.Net 中,我试图返回 BISearchResponse 中的错误节点:我能够获得在 XMLNode 中返回的 GetWireResult 节点。如何到达错误节点?

<?xml version="1.0" encoding="utf-8" ?> 
- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Body>
- <GetWireResponse xmlns="http://OpenSolutions.com/">
<GetWireResult><?xml version="1.0"?>
<BISearchResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Error xmlns="https://bixg.choicepoint.com/webservices/3.0">
<Message>BI System: Failed to Login</Message>
<Code>536870917</Code>
</Error>
</BISearchResponse>
</GetWireResult>
</GetWireResponse>
</soap:Body>
</soap:Envelope>

我的代码:XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(result);

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsmgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("ab", "http://OpenSolutions.com/");
nsmgr.AddNamespace("bg", " https://bixg.choicepoint.com/webservices/3.0");
nsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

XmlNode xmlnode = xmlDoc.DocumentElement.SelectSingleNode("/soap:Envelope/soap:Body/ab:GetWireResponse", nsmgr);

这对这里有效。.我在此处添加 xml,但它仅在编辑模式下可见。

<?xml version="1.0" encoding="utf-8" ?> 
- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Body>
- <GetWireResponse xmlns="http://OpenSolutions.com/">
<GetWireResult><?xml version="1.0"?> <BISearchResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Error xmlns="https://bixg.choicepoint.com/webservices/3.0"> <Message>BI System: Failed to Login</Message> <Code>536870917</Code> </Error> </BISearchResponse></GetWireResult>
</GetWireResponse>
</soap:Body>
</soap:Envelope>

最佳答案

在 Debug模式下,当您复制此 XML 时,请尝试选择另一个调试可视化工具,例如“文本可视化工具”。您可以单击数据提示中的放大镜图标来选择它。

我认为您的 XML 看起来像:

<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetWireResponse xmlns="http://OpenSolutions.com/">
<GetWireResult>
&lt;?xml version="1.0"?&gt;
&lt;BISearchResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;Error xmlns="https://bixg.choicepoint.com/webservices/3.0">
&lt;Message>BI System: Failed to Login&lt;/Message&gt;
&lt;Code>536870917&lt;/Code&gt;
&lt;/Error&gt;
&lt;/BISearchResponse&gt;
</GetWireResult>
</GetWireResponse>
</soap:Body>
</soap:Envelope>

<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetWireResponse xmlns="http://OpenSolutions.com/">
<GetWireResult>
<![CDATA[
<?xml version="1.0"?>
<BISearchResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Error xmlns="https://bixg.choicepoint.com/webservices/3.0">
<Message>BI System: Failed to Login</Message>
<Code>536870917</Code>
</Error>
</BISearchResponse>
]]>
</GetWireResult>
</GetWireResponse>
</soap:Body>
</soap:Envelope>

没关系。因此,您可以使用以下 XPath 选择 GetWireResult:

/soap:Envelope/soap:Body/ab:GetWireResponse/ab:GetWireResult

然后将其内容加载到新的 XML 文档中并获得所需的响应。

关于C# XPath Soap,如何导航到嵌入式节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6552135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com