gpt4 book ai didi

.net - Linq 查询从该 XML 解析/获取内容 (WSDL)

转载 作者:行者123 更新时间:2023-11-30 18:03:10 25 4
gpt4 key购买 nike

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:def="http://www.w3.org/2002/ws/databinding/examples/6/09/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<types>
<xs:schema xmlns="http://www.w3.org/2002/ws/databinding/examples/6/09/"
targetNamespace="http://www.w3.org/2002/ws/databinding/examples/6/09/"
elementFormDefault="qualified">
<xs:include xmlns:wsdl11="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap11enc="http://schemas.xmlsoap.org/soap/encoding/"
schemaLocation="http://www.w3.org/2002/ws/databinding/examples/6/09/static/Included.xsd"/>
<xs:include xmlns:wsdl11="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap11enc="http://schemas.xmlsoap.org/soap/encoding/"
schemaLocation="http://www.w3.org/2002/ws/databinding/examples/6/09/static/Included.xsd"/>
<xs:element name="echoInclude">
<xs:complexType>
<xs:sequence>
<xs:element ref="ex:include"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</types>
</definitions>

在上面的 XML 中,我想获取 xs:schema 元素内每个 xs:include 元素的 schemaLocation 属性的值

最佳答案

首先加载XML文档,设置Namespace并查询元素名称。

 XDocument doc = XDocument.Load(file);
XNamespace ns= "http://www.w3.org/2001/XMLSchema";

var nodeList = from ele in doc.Descendants(ns + "schema").Descendants(ns + "include")
select ele.Attribute("schemaLocation").Value;

foreach (var t in nodeList)
{
Console.WriteLine(t);
}

关于.net - Linq 查询从该 XML 解析/获取内容 (WSDL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8699353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com