XmlReaderSettings.IgnoreWhiteSpace或XmlDocument.PreserveWhiteSpace不能用于\ n“

时间:2012-05-29 17:23:58

标签: xml vb.net xmldocument

我有一个XML文档,它将“\ n”作为子节点读取。我试图使用以下方法删除它:

XmlReaderSettings.IgnoreWhiteSpace = True

XmlDocument.PreserveWhiteSpace = False

但它不起作用。正文后的子节点被读作“\ n”而不是<C></C>这是一段代码:

Dim xrsSettings As New XmlReaderSettings()
xrsSettings.IgnoreComments = True

Dim xrReader As XmlReader = XmlReader.Create(context.Request.InputStream, xrsSettings)
Dim xdRequest As New XmlDocument()
xdRequest.Load(xrReader)

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1">
      <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:Username>user</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
      </wsse:UsernameToken>
    </wsse:Security>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <C xmlns="http://www.sdfsfsfs.com/3939" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" MessageContentCode="8" TimeStamp="2012-05-18T08:32:42" Version="6.000">
      <A HC="ABCD">
        <B CC="EUR" End="2012-06-30" IAI="false" IC="0" MC="P1" RPC="BAR" RPT="Overlay" Start="2012-05-18" YI="false">
          <RS>
            <R CC="EUR" ITC="DR">
              <BBGAS>
                <BBGA AQC="10" AAT="300" NOG="1" />
                <BBGA AQC="10" AAT="300" NOG="2" />
                <BBGA AQC="10" AAT="300" NOG="3" />
              </BBGAS>
            </R>
          </RS>
          <D N="Short">
            <T L="DE">BAR</T>
          </D>
        </B>
      </A>
    </C>
  </SOAP-ENV:Body></SOAP-ENV:Envelope>

1 个答案:

答案 0 :(得分:0)

这种行为是正确的。如果XML中没有指定DTD(doctype声明),则为空格is not ignorableRead here了解有关解析模式和可忽略空白区域的更多信息。

虽然看起来您可能需要引入DTD来解决您的问题,但我更倾向于关注为什么您不能跳过更高级别的空白(在您的应用程序的后面),这是处理漂亮时的标准方法打印XML。