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
9
votes
1 answer

Create xmlDocument from another document

I am trying create a xmldocument object by a different XML see the code below: objNewsDoc.LoadXml(strNewsDetail); // Current XML XmlDocument docRss = new XmlDocument(); // new Xml Object i Want to create XmlElement news =…
GajendraSinghParihar
  • 9,051
  • 11
  • 36
  • 64
8
votes
2 answers

XmlDocument.Load fails, LoadXml works:

In answering this question, I came across a situation that I don't understand. The OP was trying to load XML from the following location: http://www.google.com/ig/api?weather=12414&hl=it The obvious solution is: string m_strFilePath =…
spender
  • 117,338
  • 33
  • 229
  • 351
8
votes
2 answers

remove attribute if it exists from xmldocument

How to remove the attribute from XmlDocument if attribute exists in the document? Please help. I am using RemoveAttribute but how can I check if it exists. root.RemoveAttribute(fieldName); Thanks..
nav100
  • 179
  • 1
  • 1
  • 4
8
votes
3 answers

Deleting XML using a selected Xpath and a for loop

I currently have the following code: XPathNodeIterator theNodes = theNav.Select(theXPath.ToString()); while (theNodes.MoveNext()) { //some attempts i though were close //theNodes.RemoveChild(theNodes.Current.OuterXml); …
Johnston
  • 2,873
  • 8
  • 29
  • 39
8
votes
2 answers

How do I add a custom XmlDeclaration with XmlDocument/XmlDeclaration?

I would like to create a custom XmlDeclaration while using the XmlDocument/XmlDeclaration classes in c# .net 2 or 3. This is my desired output (it is an expected output by a 3rd party app):
Metro Smurf
  • 37,266
  • 20
  • 108
  • 140
8
votes
2 answers

XML Parsing Error - C#

My code is having an XML parsing error at line 7 position 32 and I'm not really sure why Exact Error Dump 5/1/2010 10:21:42 AM System.Xml.XmlException: An error occurred while parsing EntityName. Line 7, position 32. at…
Jarred Sumner
  • 1,793
  • 6
  • 33
  • 45
8
votes
2 answers

Writing XMLDocument to file with specific newline character (c#)

I have an XMLDocument that I have read in from file. The file is Unicode, and has the newline character '\n'. When I write the XMLDocument back out, it has the newline characters '\r\n'. Here is the code, pretty simple: XmlTextWriter writer = new…
jaws
  • 1,952
  • 4
  • 20
  • 27
8
votes
3 answers

Convert XmlDocument object into an XmlNode object - C#?

How do I convert an XmlDocument to a XmlNode in C#? I need to send the entire XmlDocument object to as an input parameter to a .NET web service.
Michael Kniskern
  • 24,792
  • 68
  • 164
  • 231
8
votes
3 answers

Looping through XML document

My XML file structure looks like this: George Dsouza 320000 22 Jackie…
sujeesh
  • 488
  • 2
  • 7
  • 15
8
votes
6 answers

How to get the XPath (or Node) for the location of an XML schema validation failure?

I am using XDocument.Validate (it seems to function the same as XmlDocument.Validate) to validate an XML document against an XSD - this works well and I am informed of validation errors. However, only some information seems to be exposed [reliably]…
user166390
8
votes
3 answers

C# : the close method of Xml.Load(file)

I have written some code that loads an XML document using an XmlDocument object so as to count it's nodes. Here is the method: XmlDocument xml = new XmlDocument(); xml.Load(textBox1.Text); XmlNodeList nodes = xml.SelectNodes("//File"); foreach…
R.Vector
  • 1,669
  • 9
  • 33
  • 41
7
votes
6 answers

Parse malformed XML

I'm trying to load a piece of (possibly) malformed HTML into an XMLDocument object, but it fails with XMLExceptions... since there are extra opening/closing tags, and malformed XML tags such as instead of How do I get the XML to parse…
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
7
votes
2 answers

C#: Line information when parsing XML with XmlDocument

What are my options for parsing an XML file with XmlDocument and still retain line information for error messages later on? (as an aside, is it possible to do the same thing with XML Deserialisation?) Options seem to include: Extending the DOM and…
Nick Sonneveld
  • 3,356
  • 6
  • 39
  • 48
7
votes
2 answers

No Nodes Selected from Atom XML document using XPath?

I'm trying to parse an Atom feed programmatically. I have the atom XML downloaded as a string. I can load the XML into an XmlDocument. However, I can't traverse the document using XPath. Whenever I try, I get null. I've been using this Atom feed as…
Dan Herbert
  • 99,428
  • 48
  • 189
  • 219
7
votes
3 answers

Read First Node from XMLDocument

I receive message in XML string; that I load into XmlDocument; but second node is different every time; I have given example below are three examples: Other XML Text
Ocean
  • 655
  • 2
  • 8
  • 21