.net - 如何访问 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>
我不知道如何访问此架构中的特定元素以及命名空间如何适应。我尝试将命名空间添加到所有名称但无济于事。
有任何想法吗?
解决方案
此页面上的第一个链接是“如何查找具有特定属性 (C#) 的元素”,这似乎正是您的问题。
推荐阅读
- r - 根据条件修改特定变量的值
- asp.net - 在asp.net mvc5中成功注册后如何创建用户明智的数据库
- python - 从远程服务器获取文件路径
- razor - 获取 vorto 图像
- api - API调用适用于邮递员,但不适用于filemaker
- windows-installer - 如果文件夹被其他产品使用,如何防止卸载?
- kubernetes - 获取 ssh 访问 Kubernetes 中 Pod 的日志
- python - Seaborn:箱线图顶部的线性回归
- java - 尝试使用 HttpURLConnection 从 url 读取信息时出现 NullPointerException
- vue.js - Wordpress API 和 Vue.js 问题 - 语法的怪癖(在 v-bind:src="" 中转义冒号)