0

是否可以获得 XElement 的开始标记字符串?

例如,如果我有一个这样的 xml 元素

<Product Id="101" Name="Product 1">
    <Images>
        // ..
    </Images>
    <Description>
        // ..
    </Description>
</Product>

我只想得到开始标签:

<Product Id="101" Name="Product 1">

我将其用于验证反馈目的。

4

1 回答 1

0

使用查询

 XElement xele = XElement.Load("xmlfilename");
 XNamespace _XNamespace = XNamespace.Get("namespace url");
 IEnumerable<XElement> ProductAttribute = from ele in xele .Descendants(_XNamespace + "Product ")
                                          where ele.Attribute("Id").Value =="101" && ele.Attribute("Name") == "Product 1"
                                          select ele;

希望它对你有用

于 2013-10-03T12:27:03.093 回答