Using XDocument to read the root element from XML using C# is not showing the root element.

  • Thread starter Thread starter Satyaprakash A
  • Start date Start date
S

Satyaprakash A

Guest
Hi,

I am new to C# programming and trying to update the xml file using C#. Here when i am trying to get the root element using XDocument it is showing the complete script in the file.

Below is my code explanation:

I am having the below function and it is reading the file path from the command line arguments.

private XDocument doc;

public void Update(string filepath)
{
string filename = Path.GetFileName(filepath);

doc = xDocument.Load(filepath);

XElement rootelement = doc.Root;

}

Into the filepath variable we are taking the path "E:\\BuilderTest\\COMMON.wxs"

Then we are loading the file using XDocument.

But when we are trying to get the rootelement from the file, it is not showing the root element. Instead it is showing the complete data in the file.


But when i am using XmlDocument() instead of XDocument() I am able to see only the roor element.

Below is the code using XmlDocument():

private XmlDocument doc;

public void Update(string filepath)
{
string filename = Path.GetFileName(filepath);

doc = new XmlDocument();
doc.Load(filepath);

XmlElement rootelement = doc.DocumentElement;
}

Please help me by providing your valuable inputs on this.

Continue reading...
 

Similar threads

Back
Top