小编use*_*385的帖子

XDocument使用具有命名空间的Root元素读取XML文件

我在使用具有多个名称空间的根节点解析XML文件时遇到了一些麻烦.我想得到一个包含'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>
Run Code Online (Sandbox Code Playgroud)

我试过了:

  XDocument webXMLResource = XDocument.Load(@"../../../../Web.xml");
  IEnumerable<XElement> values = webXMLResource.Descendants("object");
Run Code Online (Sandbox Code Playgroud)

没有返回任何结果.

c# xml parsing linq-to-xml

2
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×1

linq-to-xml ×1

parsing ×1

xml ×1