Im using c#.net windows form application. I have a xml file whose name is hello.xml and it goes like this
<?xml version="1.0" encoding="utf-8" ?>
<languages>
<language>
<key>abc</key>
<value>hello how ru</value>
</language>
<language>
<key>def</key>
<value>i m fine</value>
</language>
<language>
<key>ghi</key>
<value>how abt u</value>
</language>
</languages>
How can i get the root node i.e <languages>
into a text box. At this time I will have the xml file name. i.e "hello.xml"
. Using this I should get the root node.
Using LINQ to XML you can do this:
XDocument doc = XDocument.Load("input.xml");
string rootLocalName = doc.Root.Name.LocalName;
textBox1.Text = '<' + rootLocalName + '>';
With XmlDocument you can use this:
XmlDocument doc = new XmlDocument();
doc.Load("input.xml");
string rootName = doc.SelectSingleNode("/*").Name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With