首页 > 解决方案 > 如何访问 XSDocument 元素?

问题描述

我有以下 XSD 文件,但无法获取名为“document”的内部元素:

到目前为止,我已尝试以下方法无济于事:

XDocument doc=Xdocument.Load([path]);
XNamespace ns="https://fr7.abbyy.com/FineReader_xml/FineReader10-schema-v1.xml";

------------------------------------- 所有这些我都尝试过:-------- -------------------------

var children=doc.Elements().Elements(); //here i get the immediate children, but cant filter 

var documentNode=children.Where(x=>x.Attribute("name").Value=="document").First();

var documentNode=children.Element("document");

var documentNode=children.Element(ns+"document");

XML 文件

<!--This XML file does not appear to have any style information associated with it. The document tree is shown below.-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.abbyy.com/FineReader_xml/FineReader10-schema-v1.xml" targetNamespace="http://www.abbyy.com/FineReader_xml/FineReader10-schema-v1.xml" elementFormDefault="qualified">
  <link type="text/css" id="dark-mode" rel="stylesheet" href=""/>
  <style type="text/css" id="dark-mode-custom-style"/>
  <xs:annotation></xs:annotation> 
  <xs:element name="document"><xs:element>   ----how do i get this one
  <xs:complexType name="something"></xs:complexType>
</xs:schmea>

我不知道如何访问此架构中的特定元素以及命名空间如何适应。我尝试将命名空间添加到所有名称但无济于事。

有任何想法吗?

标签: .netparsingxsd

解决方案


请在此处查看:https ://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/basic-queries-linq-to-xml

此页面上的第一个链接是“如何查找具有特定属性 (C#) 的元素”,这似乎正是您的问题。


推荐阅读