2016-07-12 20 views
-3

Ich brauche eine XML mit dieser Struktur zu schaffen: aus dieser WeiseErstellen von XML mit XmlDocument C#

<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:res="http://resource.webservice.correios.com.br/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <res:buscaEventos> 
     <usuario>ECT</usuario> 
     <senha>SRO</senha> 
     <tipo>L</tipo> 
     <resultado>T</resultado> 
     <lingua>101</lingua> 
     <objetos>JS331400752BR</objetos> 
     </res:buscaEventos> 
    </soapenv:Body> 
</soapenv:Envelope> 

aber es ist falsch:

<?xml version="1.0" encoding="utf-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:res="http://resource.webservice.correios.com.br/"> 
    <soapenv:Header /> 
    <soapenv:Body> 
    <res:buscaEventos xmlns:res="http://schemas.xmlsoap.org/soap/envelope/"> 
     <usuario>ETC</usuario> 
     <senha>SRO</senha> 
     <tipo>L</tipo> 
     <resultado>T</resultado> 
     <lingua>101</lingua> 
     <objetos>JS331400752BR</objetos> 
    </res:buscaEventos> 
    </soapenv:Body> 
</soapenv:Envelope> 

Der Unterschied in buscaEventos ist

Ich habe auf folgende Weise erstellt XmlNode eventosNode = xmlDoc.CreateElement ("res " , " buscaEventos " " http://schemas.xmlsoap.org/soap/envelope/ ") ; Wie entferne ich den xmlns: res nur diesen Knoten?

+0

https://stackoverflow.com/questions/1772004/how-can-i-make-the-xmlserializer-only-serialize-plain-xml –

+1

Google, dass zuerst bevor du hierher kommst und du wirst die Antwort bekommen; Es gibt viele Blog-Posts und SO-Posts darüber, wie man das erreicht –

Antwort

0

Der Namespace res ist im Stammverzeichnis http://resource.webservice.correios.com.br/ zugeordnet, aber wenn Sie buscaEventos erstellt haben, haben Sie es neu zugeordnet.

Dies das Problem lösen kann:

XmlNode eventosNode = xmlDoc.CreateElement("res", "buscaEventos" 
    "http://resource.webservice.correios.com.br/") ; 
+0

Tanks für Hilfe Mann :) –