簡體   English   中英

xsi:nil時使用XDocument加載XML

[英]Loading XML with XDocument when xsi:nil

我正在嘗試使用C Sharp中的XDocument讀取此XML文檔。

  <Instrument_Root>
    <Instrument_ID>123</Instrument_ID>
    <Deal_number xsi:nil="true"/>
  </Instrument_Root>

我使用下面的代碼閱讀XML文檔:

   XDocument xDoc = XDocument.Load("XMLFile1.xml");

由於xsi:nil我收到一條錯誤消息

錯誤合並:未聲明System.Xml.dll'xsi'發生類型'System.Xml.XmlException'的未處理異常。

有沒有辦法將xsi視為NULL?

謝謝

必須將命名空間前綴xsi聲明為某個位置,文檔才能被視為XML,例如:

<Instrument_Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Instrument_ID>123</Instrument_ID>
    <Deal_number xsi:nil="true"/>
</Instrument_Root>

您可以嘗試將XML文件更改為如下所示:

<Instrument_Root  xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <Instrument_ID>123</Instrument_ID>
    <Deal_number xsi:nil="true"/>
</Instrument_Root>

屏幕截圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM