我在解析具有多个命名空间的根节点的 XML 文件时遇到了一些问题。我想得到一个节点 'object' 的列表,其类型字符串包含 'UserControlLibrary':
XML 文件:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net
http://www.springframework.net/xsd/spring-objects.xsd">
<!-- master pages -->
<object type="RLN.Site, RLN">
<property name="ContainerBLL" ref="ContainerBLL"></property>
<property name="UserBLL" ref="UserBLL"></property>
<property name="TestsBLL" ref="TestsBLL"></property>
<property name="GuidBLL" ref="GuidBLL"></property>
</object>
<object type="RLN.UserControlLibrary.topleveladmin, RLN.UserControlLibrary">
<property name="ContainerBLL" ref="ContainerBLL"></property>
<property name="UserBLL" ref="UserBLL"></property>
<property name="GuidBLL" ref="GuidBLL"></property>
</object>
<object type="RLN.UserControlLibrary.topleveladminfloat, RLN.UserControlLibrary">
<property name="ContainerBLL" ref="ContainerBLL"></property>
<property name="UserBLL" ref="UserBLL"></property>
</object>
</objects>
我努力了:
XDocument webXMLResource = XDocument.Load(@"../../../../Web.xml");
IEnumerable<XElement> values = webXMLResource.Descendants("object");
没有返回结果。