简体   繁体   English

如何使用 c# linq 读取 xml 文件中的冒号

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

How can I read colon in xml file using c# linq如何使用 c# linq 在 xml 文件中读取冒号

My code in c#我在 C# 中的代码

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

The mml literal indicates the namespace used in your xml. mml文字表示您的 xml 中使用的命名空间。 You should be able to find the definition in the root node.您应该能够在根节点中找到定义。 For example, based on your comment, your root tag looks like following.例如,根据您的评论,您的根标签如下所示。

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

In order to access Element with namespace, you need to specify the namespace using XNamespace .为了使用命名空间访问 Element,您需要使用XNamespace指定命名空间。 For example,例如,

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