Questions tagged [xmldocument]

The original .NET type that represents an XML document. The more modern version is XDocument.

XmlDocument is the original .NET type that represents an XML document. The more modern version is XDocument.

Use XmlDocument.LoadXml to load an XmlDocument from a string. Use one of the XmlDocument.Load methods to load from a file path or URL, Stream, TextReader, or XmlReader.

Using XmlDocument.Load with a string containing XML will lead to the common "Data at the root level is invalid" exception.

1239 questions
40
votes
6 answers

How do I get the entire XML string from a XMLDocument returned by jQuery (cross browser)?

I have tried and failed to find out how to get the entire XML string from the XMLDocument returned by a GET. There are a lot of questions on SO on how to find or replace specific elements in the object, but I can't seem to find any answer to how to…
icecream
  • 973
  • 2
  • 12
  • 26
37
votes
5 answers

Documenting overloaded methods with the same XML comments

Say I have this constructor: /// /// Example comment. /// public SftpConnection(string host, string username, string password, int port) {...} which has these overloads: public SftpConnection(string host, string username,…
Nobody
  • 4,731
  • 7
  • 36
  • 65
37
votes
7 answers

C# hexadecimal value 0x12, is an invalid character

I am loading a lot of xml documents and some of them return errors like "hexadecimal value 0x12, is an invalid character" and there are different character. How to remove them?
Duke
  • 1,844
  • 2
  • 16
  • 26
34
votes
2 answers

Read typed objects from XML using known XSD

I have the following (as an example) XML file and XSD. 2010-02-18T01:02:03 PT10H5M3S and version="1.0" encoding="utf-8"?>
Steven_W
  • 848
  • 1
  • 7
  • 17
32
votes
5 answers

Why "Data at the root level is invalid. Line 1, position 1." for XML Document?

I am using a third-party DLL which transmits an XML document over the internet. Why would the DLL be throwing the following exception? Data at the root level is invalid. Line 1, position 1. (see below for full exception text.) Here are the first…
CJ7
  • 22,579
  • 65
  • 193
  • 321
28
votes
3 answers

How to remove all comment tags from XmlDocument

How would i go about to remove all comment tags from a XmlDocument instance? Is there a better way than retrieving a XmlNodeList and iterate over those? XmlNodeList list = xmlDoc.SelectNodes("//comment()"); foreach(XmlNode node in list) …
Filburt
  • 17,626
  • 12
  • 64
  • 115
27
votes
1 answer

Getting specified Node values from XML document

I have a problem going through an XML document (with C#) and get all the necessary values. I successfully go through all specified XmlNodeLists in the XML document, successfully get all XmlNode values inside, but I have to get some values outside of…
Mega
  • 557
  • 2
  • 10
  • 22
25
votes
1 answer

Data at the root level is invalid. Line 1, position 1 -why do I get this error while loading an xml file?

Data at the root level is invalid. Line 1, position 1 -why I get this error while load xml file this my code: XmlDocument xmlDoc=new XmlDocument(); xmlDoc.LoadXml("file.xml");
sari k
  • 2,051
  • 6
  • 28
  • 34
23
votes
5 answers

XmlDocument.Load Vs XmlDocument.LoadXml

I just came across with a problem using XmlDocument.LoadXml. The application was crashing, giving the following error: "Data at the root level is invalid. Line 1, position 1" After inspecting the XML and finding nothing wrong with it, I googled a…
Sergio
  • 8,125
  • 10
  • 46
  • 77
22
votes
2 answers

From XmlDocument To XmlReader .Net

After an advice from a user that answered to my question I'm tring to convert my XmlDocument code to XmlReader code but I'm having some troubles. This is XML (generated from php-mysql Page)…
user1107078
  • 455
  • 1
  • 7
  • 18
22
votes
7 answers

Foreach loop XmlNodeList

Currently I have the following code: XmlDocument xDoc = new XmlDocument(); xDoc.Load("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=twitter"); XmlNodeList tweets = xDoc.GetElementsByTagName("text"); foreach (int i in tweets) { …
Devator
  • 3,686
  • 4
  • 33
  • 52
21
votes
3 answers

Performance: XDocument versus XmlDocument

I have read a comparison between the two here. This is primarily a question of performance, relating to both memory and speed. I've got several XML documents that are upwards of 100 - 300 K in size. I've noticed that there is some lag when loading…
CodeMonkey1313
  • 15,717
  • 17
  • 76
  • 109
21
votes
5 answers

What is the purpose of remarks tag in c#

I understand that remarks tag is used to provide additional information about the class but it is not displayed in intellisense while hovering / calling that class. I would like to know Where exactly it is useful?
Kalyani Ramamurthy
  • 378
  • 2
  • 3
  • 13
21
votes
3 answers

How do I add multiple namespaces to the root element with XmlDocument?

I need to create an XmlDocument with a root element containing multiple namespaces. Am using C# 2.0 or 3.0 Here is my code: XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("JOBS",…
Metro Smurf
  • 37,266
  • 20
  • 108
  • 140
1
2
3
82 83