我有以下XML:如何從名稱空間的XML元素檢索記錄?
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 CDA_SDTC.xsd" xmlns="urn:hl7-org:v3" xmlns:cda="urn:hl7-org:v3" xmlns:sdtc="urn:hl7-org:sdtc">
<component>
<structuredBody>
<component>
<section>
<templateId root="abs" />
<title>A1</title>
<text>
<paragraph>Hello world!</paragraph>
</text>
</section>
</component>
</structuredBody>
</component>
</Document>
我用下面的代碼來獲取paragraph
:
XDocument m_xmld = XDocument.Load(Server.MapPath("~/xml/a.xml"));
var m_nodelist = m_xmld.Descendants().Where(p => p.Name.LocalName == "section").
Select(i => i.Element("text").Element("paragraph").Value).ToList();
錯誤:
Object reference not set to an instance of an object.
但是下面的代碼工作正常,但我想要使用上面的代碼。
XNamespace ns = "urn:hl7-org:v3";
var m_nodelist = m_xmld.Descendants(ns + "section").
Select(i => i.Element(ns + "text").Element(ns + "paragraph").Value).ToList();
我的XML文件太大,如何將其轉換成字符串「串x」 –
又是怎樣從我答的是差異.. – Anirudha
我問題編輯 –