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
21
votes
6 answers

Comparing XmlDocument for equality (content wise)

If I want to compare the contents of a XMlDocument, is it just like this? XmlDocument doc1 = GetDoc1(); XmlDocument doc2 = GetDoc2(); if(doc1 == doc2) { } I am not checking if they are both the same object reference, but if the CONTENTS of the…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
19
votes
3 answers

How to remove all child nodes of an XmlElement, but keep all attributes?

How to remove all child nodes of an XmlElement, but keep all attributes? Note, that XmlElement.RemoveAll also removes all attributes. What is a clean, elegant and well-performing way to remove all child nodes? In other words, what is best-practice…
usr
  • 168,620
  • 35
  • 240
  • 369
19
votes
4 answers

Can't get XmlDocument.SelectNodes to retrieve any of my nodes?

I'm trying to parse an XML document. The document in question is an AppxManifest file. An example document looks like this:
Earlz
  • 62,085
  • 98
  • 303
  • 499
18
votes
1 answer

Serialize object to XmlDocument

In order to return useful information in SoapException.Detail for an asmx web service, I took an idea from WCF and created a fault class to contain said useful information. That fault object is then serialised to the required XmlNode of a thrown…
Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
18
votes
2 answers

Creating an XML document using namespaces in Java

I am looking for example Java code that can construct an XML document that uses namespaces. I cannot seem to find anything using my normal favourite tool so was hoping someone may be able to help me out.
adam
  • 22,404
  • 20
  • 87
  • 119
18
votes
6 answers

Reading XML with an "&" into C# XMLDocument Object

I have inherited a poorly written web application that seems to have errors when it tries to read in an xml document stored in the database that has an "&" in it. For example there will be a tag with the contents: "Prepaid & Charge". Is there some…
Ryan Skarin
  • 3,087
  • 3
  • 21
  • 18
17
votes
4 answers

how to save xmldocument to a stream

I've already written code to parse my xml file with an XmlReader so I don't want to rewrite it. I've now added encryption to the program. I have encrypt() and decrypt() functions which take an xml document and the encryption algorithm. I have a…
user1711383
  • 778
  • 2
  • 11
  • 20
16
votes
5 answers

C# : Modify a xml node

i have that xml file : Alarm1 Desc1 1 None
BOSS
  • 1,828
  • 11
  • 34
  • 60
16
votes
7 answers

Using XPath to parse an XML document

Lets say I have the following xml (a quick example) one two I am trying to parse this by using XmlDocument and XPath (ultimately so I can make a list of…
musefan
  • 47,875
  • 21
  • 135
  • 185
15
votes
2 answers

Is there any way to save an XmlDocument *without* indentation and line returns?

All my searches have brought up people asking the opposite, but I have a file which grows by nearly 50% if it is saved with line returns and indentation. Is there any way round this? EDIT I'm not talking about opening a file, but saving one. This…
Benjol
  • 63,995
  • 54
  • 186
  • 268
15
votes
3 answers

How to add xmlnamespace to a xmldocument

Im trying to create a xml the should look like this
CruelIO
  • 18,196
  • 16
  • 40
  • 58
14
votes
3 answers

C# XMLDocument to DataTable?

I assume I have to do this via a DataSet, but it doesn't like my syntax. I have an XMLDocument called "XmlDocument xmlAPDP". I want it in a DataTable called "DataTable dtAPDP". I also have a DataSet called "DataSet dsAPDP". - if I do DataSet…
Matt Dell
  • 9,205
  • 11
  • 41
  • 58
14
votes
2 answers

XmlNode.SelectSingleNode syntax to search within a node in C#

I want to limit my search for a child node to be within the current node I am on. For example, I have the following code: XmlNodeList myNodes = xmlDoc.DocumentElement.SelectNodes("//Books"); foreach (XmlNode myNode in myNodes) { …
user31673
  • 13,245
  • 12
  • 58
  • 96
14
votes
2 answers

Search for nodes by name in XmlDocument

I'm trying to find a node by name in an XmlDocument with the following code: private XmlNode FindNode(XmlNodeList list, string nodeName) { if (list.Count > 0) { foreach (XmlNode node in list) { if…
RajenK
  • 1,403
  • 3
  • 15
  • 25
13
votes
6 answers

ImportNode creates empty xmlns attribute

Regrading this code: var tmpNewNode = xdoc.ImportNode(newNode, true); if (oldNode.ParentNode != null) { oldNode.ParentNode.ReplaceChild(tmpNewNode, oldNode); return true; } tmpNewNode is created with empty xmlns…
Guy
  • 915
  • 2
  • 14
  • 27
1 2
3
82 83