xmldocument

Load an XmlNodeList into an XmlDocument without looping?

I originally asked this question on RefactorMyCode, but got no responses there... Basically I'm just try to load an XmlNodeList into an XmlDocument and I was wondering if there's a more efficient method than looping. Private Function GetPreviousMonthsXml(ByVal months As Integer, ByVal startDate As Date, ByVal xDoc As XmlDocument, ByVa...

Removing nodes from an XmlDocument

The following code should find the appropriate project tag and remove it from the XmlDocument, however when I test it, it says: The node to be removed is not a child of this node. Does anyone know the proper way to do this? public void DeleteProject (string projectName) { string ccConfigPath = ConfigurationManager.AppSettings["Con...

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 secret simple thing to do to have it not get an error parsing that character, or am I mis...

How to prevent blank xmlns attributes in output from .NET's XmlDocument?

When generating XML from XmlDocument in .NET, a blank xmlns attribute appears the first time an element without an associated namespace is inserted; how can this be prevented? Example: XmlDocument xml = new XmlDocument(); xml.AppendChild(xml.CreateElement("root", "whatever:name-space-1.0")); xml.DocumentElement.AppendChild(xml.Crea...

How would you compare two XML Documents?

As part of the base class for some extensive unit testing, I am writing a helper function which recursively compares the nodes of one XmlDocument object to another in C# (.NET). Some requirements of this: The first document is the source, e.g. what I want the XML document to look like. Thus the second is the one I want to find differ...

Dataset ReadXmlSchema Errors

How is it possible for this to be true XmlDocument d = BuildReportXML(schema); DataSet ds = new DataSet(); ds.ReadXmlSchema(schema); ds.ReadXml(new XmlNodeReader(d)); schema is the schema location that I apply to the xmldocument before I start setting data, assuring that all the columns are of the correct type. Then I set the schema t...

What is the simplest way to get indented XML with line breaks from XmlDocument?

When I build XML up from scratch with XmlDocument, the OuterXml property already has everything nicely indented with line breaks. However, if I call LoadXml on some very "compressed" XML (no line breaks or indention) then the output of OuterXml stays that way. So ... What is the simplest way to get beautified XML output from an instan...

What is the best way to sort nodes in an XmlDocument? (.Net)

I was using an XSL style sheet to do the sorting but it seems to be very slow. Is there a more efficient way? It is a flat list of nodes, if I convert the nodes to an object and sort in a GenericList would it help? EDIT I don't need the end result to be XML. ...

Implementing GetByClassName for a .Net XmlDocument.

I am using an XmlDocument to parse and manipulate an XHTML string, converting some nodes to non-HTML nodes. What is the best way to get a list of all nodes with a given class name? Can it be done with XPath? ...

.NET XmlDocument : Why DOCTYPE changes after Save?

I am opening a XML file using .NET XmlReader and saving the file in another filename and it seems that the DOCTYPE declaration changes between the two files. While the newly saved file is still valid XML, I was wondering why it insisted on changing original tags. Dim oXmlSettings As Xml.XmlReaderSettings = New Xml.XmlReaderSettings() oX...

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", "http://www.example.com"); doc.AppendChild(root); XmlElement job = doc.CreateElement("JOB", "http://www.example.com"); root.Append...

what is the best way to update an XML node value in C#?

My function iterates through every node of an instance of an XMLDocument. It checks to see if the current node's name is in a lookup list. If it is, it applies appropriate validation to the value of the current node. When the validation method indicates that the value has been changed, I want to replace the value in the original docum...

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): <?xml version="1.0" encoding="ISO-8859-1" ?> <?MyCustomNameHere attribute1="val1" attribute2="val2" ?> [ ...more xml... ] Using the XmlDocument/...

Unwanted xmlns="" in _di_IXMLNode

I'm creating a xml-file for display in Excel using _di_IXMLDocument. But for some tags I get an unwanted extra (empty) xmlns attribute witch makes the file unreadable for Excel... This is what i do: ... _di_IXMLNode worksheet = workbook->AddChild("Worksheet"); worksheet->SetAttribute("ss:Name",Now().DateString()); ... and this is what...

Merge and override .NET configuration files with C#

I wrote this piece of code to merge two .NET configuration files: Add non existent nodes and override values on existing ones. I avoided to use the much faster reader/writer way because the app I'm using it for is not performance critical. What do you think of this? using System; using System.Xml; namespace devcoach.FrameworkExtension...

XmlDocument and slow schema processing

I have an xml template document that I need to load into an XmlDocument. eg myXMLDocument.Load(myXMLFile); However this is very slow as it loads in the dtd. I have tried both "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" and a local copy of the dtd. Both take more or less the same time. If I turn of loading the dtd by setting the ...

XmlDocument and the Formal Public Identifier

Why is my GetEntity function in my overloaded XmlResolver being passed the Formal Public Identifier when I load an xml file into an XmlDocument? Is this a bug or am I supposed to deal with this some how? edit: Here's some code. Say for example I do this: XmlDocument myXmlDoc = new XmlDocument(); myXmlDoc.XmlResolver = new MyXmlResolv...

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 a test: http://steve-yegge.blogspot.com/feeds/posts/default Calling SelectSingleNode()...

Reading the StackOverflow RSS feed

I'm trying to get a list of unanswered questions from the feed but am having trouble reading it. const string RECENT_QUESTIONS = "http://stackoverflow.com/feeds"; XmlTextReader reader; XmlDocument doc; // Load the feed in reader = new XmlTextReader(RECENT_QUESTIONS); //reader.MoveToContent(); // Add the feed to the document doc = new...

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. ...