i have got a object of attribute and i want to know what is its node name (who contain this attribut) .. please give me solution (vb.net preferable)..
+3
A:
Lets say I think I know what you want. The name of the node from a given attribute.
How about something like
Dim s As String = "<nodelist><node><val id=""test""/></node></nodelist>"
Dim doc As New XmlDocument()
doc.LoadXml(s)
Dim attribute As XmlAttribute = doc.SelectSingleNode("//nodelist/node/val").Attributes(0)
Dim name As String = attribute.OwnerElement.Name
astander
2009-12-30 13:09:28
exactly.. what i am looking for....thanks lot.... you guys are doing great job.. you should be proud of it..
Rajesh Rolen- DotNet Developer
2009-12-30 13:11:34
+1
A:
With XmlDocument
:
string xml = @"<xml><el att=""abc""/></xml>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlAttribute attr = (XmlAttribute)
doc.SelectSingleNode("//@att");
string elName = attr.OwnerElement.Name;
or with XDocument
:
string xml = @"<xml><el att=""abc""/></xml>";
XDocument doc = XDocument.Parse(xml);
XAttribute attr = ((XElement)doc.Root.FirstNode).FirstAttribute;
string elName = attr.Parent.Name.LocalName;
Marc Gravell
2009-12-30 13:09:53