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 に答える