0

Is possible to get the start tag string of an XElement?

For example, if i have an xml element like this

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

i want to get only the start tag:

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

I use this for validation feedback purposes.

Catalin
  • 11,503
  • 19
  • 74
  • 147

1 Answers1

0

use query like

 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;

Hope it will work for you

Mansinh
  • 1,365
  • 4
  • 19
  • 47