我的代码需要一些帮助。我发现这样的XML文档:
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="urn:microsoft-dynamics-schemas/codeunit/Prueba" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/Prueba">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/Prueba">
<element name="FuncionPublica">
<complexType>
<sequence/>
</complexType>
</element>
<element name="FuncionPublica_Result">
<complexType>
<sequence/>
</complexType>
</element>
<element name="FuncionParam">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="parametro1" type="int"/>
</sequence>
</complexType>
</element>
<element name="FuncionParam_Result">
<complexType>
<sequence/>
</complexType>
</element>
<element name="FuncionVar">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="num" type="int"/>
</sequence>
</complexType>
</element>
<element name="FuncionVar_Result">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="num" type="int"/>
</sequence>
</complexType>
</element>
<element name="FuncionReturn">
<complexType>
<sequence/>
</complexType>
</element>
<element name="FuncionReturn_Result">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="return_value" type="int"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="FuncionPublica">
<part name="parameters" element="tns:FuncionPublica"/>
</message>
<message name="FuncionPublica_Result">
<part name="parameters" element="tns:FuncionPublica_Result"/>
</message>
<message name="FuncionParam">
<part name="parameters" element="tns:FuncionParam"/>
</message>
<message name="FuncionParam_Result">
<part name="parameters" element="tns:FuncionParam_Result"/>
</message>
<message name="FuncionVar">
<part name="parameters" element="tns:FuncionVar"/>
</message>
<message name="FuncionVar_Result">
<part name="parameters" element="tns:FuncionVar_Result"/>
</message>
<message name="FuncionReturn">
<part name="parameters" element="tns:FuncionReturn"/>
</message>
<message name="FuncionReturn_Result">
<part name="parameters" element="tns:FuncionReturn_Result"/>
</message>
<portType name="Prueba_Port">
<operation name="FuncionPublica">
<input name="FuncionPublica" message="tns:FuncionPublica"/>
<output name="FuncionPublica_Result" message="tns:FuncionPublica_Result"/>
</operation>
<operation name="FuncionParam">
<input name="FuncionParam" message="tns:FuncionParam"/>
<output name="FuncionParam_Result" message="tns:FuncionParam_Result"/>
</operation>
<operation name="FuncionVar">
<input name="FuncionVar" message="tns:FuncionVar"/>
<output name="FuncionVar_Result" message="tns:FuncionVar_Result"/>
</operation>
<operation name="FuncionReturn">
<input name="FuncionReturn" message="tns:FuncionReturn"/>
<output name="FuncionReturn_Result" message="tns:FuncionReturn_Result"/>
</operation>
</portType>
<binding name="Prueba_Binding" type="tns:Prueba_Port">
<binding xmlns="http://schemas.xmlsoap.org/wsdl/soap/" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="FuncionPublica">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:microsoft-dynamics-schemas/codeunit/Prueba:FuncionPublica" style="document"/>
<input name="FuncionPublica">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</input>
<output name="FuncionPublica_Result">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</output>
</operation>
<operation name="FuncionParam">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:microsoft-dynamics-schemas/codeunit/Prueba:FuncionParam" style="document"/>
<input name="FuncionParam">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</input>
<output name="FuncionParam_Result">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</output>
</operation>
<operation name="FuncionVar">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:microsoft-dynamics-schemas/codeunit/Prueba:FuncionVar" style="document"/>
<input name="FuncionVar">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</input>
<output name="FuncionVar_Result">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</output>
</operation>
<operation name="FuncionReturn">
<operation xmlns="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="urn:microsoft-dynamics-schemas/codeunit/Prueba:FuncionReturn" style="document"/>
<input name="FuncionReturn">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</input>
<output name="FuncionReturn_Result">
<body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</output>
</operation>
</binding>
<service name="Prueba">
<port name="Prueba_Port" binding="tns:Prueba_Binding">
<address xmlns="http://schemas.xmlsoap.org/wsdl/soap/" location="http://pcnav02.datanet.local:7017/DynamicsNAV100/WS/CRONUS%20Espa%C3%B1a%20S.A./Codeunit/Prueba"/>
</port>
</service>
</definitions>
所以,我需要获取元素中的值 parametro1 ,其名称为“FuncionParam”,然后位于sequence / complexType / element
foreach (XmlNode node in docXML.GetElementsByTagName("sequence"))
{
XmlNodeList lstElements = node.ChildNodes;
for (int j = 0; j < lstElements.Count; j++)
{
Console.WriteLine("{0}", node.InnerXml);
}
}
上面的代码显示了以下结果:
<element minOccurs="1" maxOccurs="1" name="parametro1" type="int"
xmlns="http://www.w3.org/2001/XMLSchema" />
我需要获得该值, parametro1 但首先我需要搜索名称= “FuncionParam”。
答案 0 :(得分:0)
您可以检查GetElementsByXpath
吗?在xpath下方使用: -
//element[@name='FuncionParam']//sequence
它将返回: -
Element=<sequence xmlns="http://www.w3.org/2001/XMLSchema">
<element maxOccurs="1" minOccurs="1" name="parametro1" type="int"/>
</sequence>
希望它会对你有所帮助:)。