xmldocument

What is wrong in my XPath?

Hi! Here I have the xml: <root> <field ...>offer</field> <field type="ferrari" ...>car</field> <field ...>company</field> <field ...>whatever</field> </root> and I want to know the «type» of the «car» by extracting the element. I thought something like this: /root[field='car']/field (or /root[field='car']) was enoug...

Convert XmlDocument to FileInfo

I have a web service which returns a string representing an Xml file. The string is properly formed xml. I need to create FileInfo object from the string so that I can deserialize it. I don't have the file path or even if i do thats of no use as it is a disconnected server. I can convert string to XmlDocument by - XmlDocument doc = n...

How to add a System.Xml.XmlDocument type to applications state

I am using Asp.net 3.5 and C# I have to add an XmlDocument to my application state so that everytime my application doesnt access the XML file on my filesystem, I will add this at the Application_Start() function in Global.asax.cs I am adding this to system state as : protected void Application_Start(Object sender, EventArgs e) { ...

How can I add new root element to a C# XmlDocument ?

I have, outside of my control, an XmlDocument which has a structure like the following: <parent1> ...minor amount of data... </parent1> I have another XmlDocument, also outside of my control, which has the following structure: <parent2> ..very large amount of data... </parent2> I need an XmlDocument in the format: <parent1> ...min...

Read typed objects from XML using known XSD

I have the following (as an example) XML file and XSD. <?xml version="1.0" encoding="utf-8" ?> <foo> <DateVal>2010-02-18T01:02:03</DateVal> <TimeVal>PT10H5M3S</TimeVal> </foo> and version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSc...

XmlDocument::Save() appends the xml in file

I want to keep a single XmlDocument object in a class and let methods make changes to it and save it. using (FileStream fs = new FileStream(@"D:\Diary.xml", FileMode.Open, FileAccess.ReadWrite, FileShare.Read)) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fs);...

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

Convert XmlDocument to String

Here is how I'm currently converting XMLDocument to String StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter); xmlDoc.WriteTo(xmlTextWriter); return stringWriter.ToString(); The problem with this method is that if I have " ((quotes) which I have in attributes) it escapes the...

XmlDocument from LINQ to XML query

I am loading an XML document into an XDocument object, doing a query and then returning the data through a web service as an XmlDocument object. The code below works fine, but it just seems a bit smelly. Is there a cleaner way to take the results of the query and convert back to an XDocument or XmlDocument? XDocument xd = X...

How to migrate from XslTransform to XslCompiledTransform

I have the following code that I need to migrate from VS 2003 (.Net 1.1) to VS 2008 (.Net 2+) but I get compilation error - System.Xml.Xsl.XslTransform' is obsolete: This class has been deprecated. I probably need to use System.Xml.Xsl.XslCompiledTransform instead. but I do not find the matching Load() and Transform() overload versions...

XmlDocument OuterXml pretty printed

Hi, I've got a XmlDocument and I want to get the Content (OuterXml) as a pretty printed string. How can I do this? Regards ...

In loaded object model prefix XmlDocument elements with namespace

I have a "plain" XmlDocument loaded like so: <root> <element1 /> <element2></element2> </root> and want to qualify the elements with namespaces like so while the object model is loaded <abc:root xmlns:abc="urn:something"> <abc:element1 /> <abc:element2></abc:element2> </abc:root> before writing it out. ...

XmlDocument SelectNodes(Xpath): Order of result

This is an example xml from MSDN <?xml version="1.0"?> <!-- A fragment of a book store inventory database --> <bookstore xmlns:bk="urn:samples"> <book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8"> <title>Pride And Prejudice</title> </book> <book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1"> ...

How to modify exiting XML file with XmlDocument and XmlNode in C#

I already implemented to create the XML file below with XmlTextWriter when application initialization. And know I don't know how to update the childNode id value with XmlDocument & XmlNode. Is there some property to update the id value? I tried InnerText but failed. thank you. <?xml version="1.0" encoding="UTF-8"?> <Equipment xmlns...

XmlDocument caching memory usage

We are seeing very high memory usage in .NET web applications which use XmlDocument. A small (~5MB) XML document is loaded into an XmlDocument object and stored in HttpContext.Cache for easy querying and XSLT transformation on each page load. The XML is modified on disk periodically so a cache has a dependency on the file. Such an appli...

XmlDocument SelectSingleNode of improperly formed XML

I have a XmlDocument which is not properly formed <library> <dept> <books></books> <language></language> </dept> <dept> <lecturer></lecturer> </dept> </library> I want to do a XmlDocument.SelectSingleNode for 'lecturer' tag. When I select ChildNodes of <library> tag, I get only <books> and <language> but not <lec...

XML and .NET: How to replace specific node with many other ones loaded from raw xml data

Let's suppose we have an element like this one in the main xml file: <group name="gr1" filename="groups/gr1.xml"/>. The second file gr1.xml contains something like this: <item name="i1">Item one</item> <item name="i2">Item two</item> <item name="i3">Item three</item> Note that there is no XML declaration in gr1.xml, just plain items w...

Is XMLDocument.Save an atomic operation?

Is there anyway another process monitoring for files created using XMLDocument.Save() could encounter a partial file? Does it make any difference if Save() is overwriting an existing file? ...

How to select nodes where node name contains "mystring"

I need to get XmlNodeList where node name contains "mystring" XML <?xml version="1.0" encoding="utf-8"?> <root> <node1> node1 value </node1> <node2_mystring> node2 value </node2_mystring> <node3> node3 value </node3> <node4_mystring> node 4 value </node4_mystring> </root> Desired output is <?xml ...

What are the advantages to use StringBuilder versus XmlDocument or related to create XML documents?

This might be a bit of a code smell, but I have seen it is some production code, namely the use of StringBuilder as opposed to XmlDocument when creating XML documents. In some cases these are write once operations (e.g. create the document and save it to disk) where as others are passing the built string to an XmlDocument to preform an X...