Tag: xpath

从XML文档中提取元素

有人可以告诉我如何使用.NET 3.5框架下的XPath和C#从下面的XML中提取Errors元素吗? COMPANY NAME FIELD IS INVALID

从XmlDataSource填充DropDownList

我想使用一个简单的xml文件填充我的DropDownList: foo bar baz 我的XPath是 /Databases/Database 我的下拉列表呈现为: System.Web.UI.WebControls.XmlDataSourceNodeDescriptor System.Web.UI.WebControls.XmlDataSourceNodeDescriptor System.Web.UI.WebControls.XmlDataSourceNodeDescriptor 我该如何提取文字? 谢谢

如何从C#中匹配XPath查询的XML文件中获取值

我想知道是否有一种方法使用C#,这使我能够返回匹配给定XPath查询的XML文件中的所有内部值。 假设我们有以下名为exampleWithFruits.xml的Xml文件: 如下所示: string xmlFilePath = “exampleWithFruits.xml”; string xPathQuery = “//fruits/apples//@color” string[] matchingValues = interestingFunction(xmlFilePath, xPathQuery); //for instance we would get something like : matchingValues = {red, red, green, yellow} 总而言之,我想知道如何创建一个像interestingFunction这样的函数 谢谢

在C#中解析MS Word生成的XML文件

所以我有一个客户端(这可能只来自政府),他们有一堆他们想要输入数据库的MS Word文档,而且没有人工输入,我觉得将它们转换为XML并使用实用程序解析它们会是最好的行动方案。 我有一个实用程序,使用stackoverflow上的代码执行此操作: Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); object oMissing = System.Reflection.Missing.Value; DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(“\\testfiles”)); FileInfo[] wordFiles = dirInfo.GetFiles(“*.doc”); word.Visible = false; word.ScreenUpdating = false; XmlDocument xmlDoc = new XmlDocument(); foreach(FileInfo wordFile in wordFiles) { Object filename = (Object)wordFile.FullName; Document doc = word.Documents.Open(ref filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref […]

使用命名空间别名而不是XElement上的URI选择命名空间的XML节点属性

我正在尝试从严格命名的XML文档中查询一些信息,并且在查找也是命名空间的属性时遇到了一些麻烦。 XML看起来像: … 我的目标是创建一个包含国家/地区代码和国家/地区名称的对象列表。 这对我现在有用: XmlReader reader = XmlReader.Create(@”path/to/xml.xml”); XDocument root = XDocument.Load(reader); XmlNameTable nameTable = reader.NameTable; XmlNamespaceManager nsManager = new XmlNamespaceManager(nameTable); nsManager.AddNamespace(“rdf”, “http://www.w3.org/1999/02/22-rdf-syntax-ns#”); nsManager.AddNamespace(“rdfs”, “http://www.w3.org/2000/01/rdf-schema#”); nsManager.AddNamespace(“skos”, “http://www.w3.org/2004/02/skos/core#”); nsManager.AddNamespace(“geo”, “http://www.geonames.org/ontology#”); var geoCountries = from country in root.XPathSelectElements(“./rdf:RDF/geo:Country”, nsManager) select new { CountryCode = country.Attributes(“{http://www.w3.org/2004/02/skos/core#}notation”).First().Value, CountryName = country.Attributes(“{http://www.w3.org/2000/01/rdf-schema#}label”).First().Value }; 这工作正常,但我想使用命名空间别名找到属性,而不是命名空间URI(只是因为),或者至少能够使用别名查找URI。 为了尝试后一种想法,我最终想通了我可以做到这一点: country.Attributes(nsManager.LookupNamespace(“skos”) + “notation”).First().Value 但是我得到一个XmlException :’:’字符,hex值0x3A,不能包含在名称中。 […]

如何在.Net Core 1.0中使用XPathSelectElement?

在.Net 4.X ,此扩展方法位于System.Xml.XPath下。 但是,我想知道如何在.Net Core中找到/使用它? 我有一个类库。 移植工具不显示有关XPathSelectElement任何信息。 或者.Net核心中的任何替代品? 非常感谢!

如何使用SelectSingleNode获取属性值?

我正在解析一个xml文档,我需要找出gid(属性)值(3810)。 基于SelectSingleNode() 。 我发现找到属性名称和它的值并不容易。 我可以使用此方法还是必须切换到其他方式。 附上是我的代码。 如何使用book obj获取gid的属性值3810 。 谢谢。 我的test.xml文件如下 我写了test.cs如下 public class Sample { public static void Main() { XmlDocument doc = new XmlDocument(); doc.Load(“test.xml”); XmlNode book; XmlNode root = doc.DocumentElement; book = root.SelectSingleNode(“Attributes[AttrDir[@name=’EFEM’]/AttrDir[@name=’Aligner’]/AttrDir[@name=’SequenceID’]/AttrObj[@text=’Slot01′]]”); Console.WriteLine(“Display the modified XML document….”); doc.Save(Console.Out); } } [更新06/10/2010] xml文件是一个复杂的文件。 包括数以千计的gids。 但对于每个Xpath,gid都是独一无二的。 我将xml文件加载到TreeView控件。 this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect); 。 发生treeView1_AfterSelect事件时, […]

WPF,在XAML中使用XPath和XmlDataProvider根据ComboBox中的选定值选择节点

这个问题与我之前的问题有关,但更具体。 假设我有两个ComboBox,一个填充了产品名称,另一个是空的。 选择产品时,我希望第二个ComboBox填充与该产品相关的数据。 我有以下XML: …more Component nodes… …more Product nodes… 我希望能够以某种方式在Component ComboBox上设置XPath ,以便从Product节点获取其@name属性等于Product ComboBox中当前选定值的所有Components/Component节点。 这可能吗? 我该怎么办? 这是我到目前为止在XAML中的内容: Product ComboBox中填充了MyProduct1等产品名称,因此该部分很好。 这是我需要帮助的依赖组件ComboBox。

C#如何提取完整的xml节点集

Everyday Italian Giada De Laurentiis 2005 30.00 Harry Potter J K. Rowling 2005 29.99 XQuery Kick Start James McGovern Per Bothner Kurt Cagle James Linn Vaidyanathan Nagarajan 2003 49.99 Learning XML Erik T. Ray 2003 39.95 他们以任何方式使用XPath来选择完整的第一个节点集,例如来自 to , 这样,可以存储那个xml块供以后使用。 鲍勃。

DataGrid – “双向绑定需要Path或XPath。”

我想在DataGrid上显示我的对象数据库 public class Student { public string Imie { get; set; } public string Nazwisko { get; set; } string Numer { get; set; } internal List Telefony { get; set; } internal Adres Adres { get; set; } } 在Adres和Telefon课程中,我显然有一些额外的领域。 我的XAML: 我可以很容易地设置Imie , Nazwisko和Numer字段但是当我试图设置Ulica的值( Adres类中的字段)编译器给我这个例外: InvalidOperationException was unhandled Two-way binding requires Path or XPath. […]