【发布时间】:2011-07-01 18:55:33
【问题描述】:
在 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>
【问题讨论】:
-
我将您的 XML 示例放入 {code} 部分。请下次执行此操作,否则 XML 不会(正确)显示。
-
在编辑模式下,粘贴您的 XML,然后选择它并按“{}”按钮。您将看到代码显示在预览中。然后保存。代码现在将在编辑模式之外正确显示。
-
如果您将其缩进以使层次结构易于查看,也会有所帮助。
-
我认为,SOAP 主体
<GetWireResult>中的内容是经过编码的 XML,因此它不是 XML 的一部分。 -
既然是 xml 编码,那么一种方法是取消编码,将其加载到 xmlDocument 对象中并继续解析吗?