簡體   English   中英

如何使用 c# linq 讀取 xml 文件中的冒號

[英]How to read colon in xml file using c# linq

如何使用 c# linq 在 xml 文件中讀取冒號

我在 C# 中的代碼

XDocument xdocc = XDocument.Load(files, LoadOptions.SetLineInfo);
var mml_hi_it = xdocc.Descendants("mml:hi").Where(s => (string)s.Attribute("rend").Value == "it");

mml文字表示您的 xml 中使用的命名空間。 您應該能夠在根節點中找到定義。 例如,根據您的評論,您的根標簽如下所示。

<article article-type="research-article" dtd-version="1.1" xml:lang="en" xmlns:mml="w3.org/1998/Math/MathML" xmlns:xlink="w3.org/1999/xlink" xmlns:oasis="niso.org/standards/z39-96/ns/oasis-exchange/table">  

為了使用命名空間訪問 Element,您需要使用XNamespace指定命名空間。 例如,

XNamespace  mml = "w3.org/1998/Math/MathML";
var mml_hi_it = xdocc.Descendants(mml + "hi").Where(s => (string)s.Attribute("rend").Value == "it");

暫無
暫無

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

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