【问题标题】:Create XML with XmlDocument C# [duplicate]使用 XmlDocument C# 创建 XML [重复]
【发布时间】:2016-11-14 22:47:57
【问题描述】:

我需要创建一个具有这种结构的 XML:

<?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>

但是这样就错了:

<?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>

区别在于buscaEventos

我通过以下方式创建 XmlNode eventosNode = xmlDoc.CreateElement ( "res " , " buscaEventos " " http://schemas.xmlsoap.org/soap/envelope/ " ) ; 如何删除 xmlns : res only that node?

【问题讨论】:

标签: c# xml xmldocument


【解决方案1】:

res 命名空间映射到根目录下的http://resource.webservice.correios.com.br/,但是当您创建 buscaEventos 时,您重新映射了它。

这可能会解决问题:

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

【讨论】:

  • 坦克寻求帮助 :)
猜你喜欢
  • 2012-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-07
相关资源
最近更新 更多