xmldocument

Create or replace node in an XML without root in C#

大兔子大兔子 提交于 2021-02-20 18:55:46
问题 I have an XML file like this: <Something>....</Something> <Another>....</Another> <Other>...</Other> This XML file does not have a root element (I know that this is a wrong XML format). I need to create or replace (if it already exists) a node in this XML, but I can't work with XDocument or XmlDocument because they need a root element to work, and I can't add a root element to this XML because I can't change more code in the Application (Windows forms application). What are my options to

Create or replace node in an XML without root in C#

好久不见. 提交于 2021-02-20 18:54:12
问题 I have an XML file like this: <Something>....</Something> <Another>....</Another> <Other>...</Other> This XML file does not have a root element (I know that this is a wrong XML format). I need to create or replace (if it already exists) a node in this XML, but I can't work with XDocument or XmlDocument because they need a root element to work, and I can't add a root element to this XML because I can't change more code in the Application (Windows forms application). What are my options to

Create or replace node in an XML without root in C#

一笑奈何 提交于 2021-02-20 18:54:03
问题 I have an XML file like this: <Something>....</Something> <Another>....</Another> <Other>...</Other> This XML file does not have a root element (I know that this is a wrong XML format). I need to create or replace (if it already exists) a node in this XML, but I can't work with XDocument or XmlDocument because they need a root element to work, and I can't add a root element to this XML because I can't change more code in the Application (Windows forms application). What are my options to

Efficient way to read large XML into dfferent node types in C#

浪尽此生 提交于 2021-02-15 07:53:27
问题 I am new to C#. I have a relatively large XML file (28MB) and am trying to parse its subtrees into several different types based on their content. Essentially, I have 6900+ Content nodes that all have to be interrogated to figure out what type they are. <Collections> <Content>..</Content> <Content>..</Content> <Content>..</Content> ... </Collections> For each Content node, the variety of nodes below it can have 1 of 3 different patterns. I have to look into the node to decide which pattern

“Any public static members of XmlDocument are thread safe. Any instance members are not guaranteed to be thread safe” : yes, but

廉价感情. 提交于 2021-02-10 14:19:42
问题 I see in the XmlDocument class documentation on MSDN that Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe. Same thing for the XmlNodeList class. I am using those classes in the following context. Inside a Parallel.Foreach I do : X MyX = new X(); string XMLstring = MyX.GetXML(ID, true); XmlDocument doc = new XmlDocument(); doc.LoadXml(XMLstring); XmlNodeList nodeList = doc.SelectNodes("blah/secondblah")

XPath find all matches C# XmlDocument

◇◆丶佛笑我妖孽 提交于 2021-02-07 19:14:42
问题 I am trying to figure out how to find all matches of string in a XmlDocument . XmlNodeList results = document.SelectNodes("Products/Product/fn:matches(.,'" + SearchWord + "')"); Im trying to compare the innerText of Product. The above example don't work though, but I guess my way of using XPath functions are very wrong. 回答1: Evaluate this XPath 1.0 expression (did you know matches() is an XPath 2.0 function and isn't supported in .NET): Products/Product/descendant::*[contains(text(),

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

≡放荡痞女 提交于 2021-02-07 05:19:17
问题 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 code reproduces the 'bug' for me: var path = @"C:\test.xml"; System.IO.File.WriteAllText(path, "<root>\r\n\t<line></line>\r\n\t<line></line>\r\n</root>"); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.PreserveWhitespace = false; doc

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

佐手、 提交于 2021-02-07 05:16:17
问题 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 code reproduces the 'bug' for me: var path = @"C:\test.xml"; System.IO.File.WriteAllText(path, "<root>\r\n\t<line></line>\r\n\t<line></line>\r\n</root>"); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.PreserveWhitespace = false; doc

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

柔情痞子 提交于 2021-02-07 05:16:04
问题 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 code reproduces the 'bug' for me: var path = @"C:\test.xml"; System.IO.File.WriteAllText(path, "<root>\r\n\t<line></line>\r\n\t<line></line>\r\n</root>"); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.PreserveWhitespace = false; doc

How to dispose XmlDocument

三世轮回 提交于 2020-05-29 06:40:12
问题 I am creating a XmlDocument using a stream and do some changes in the XmlDocument and save the XmlDocument to the stream itself. XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(fileStream); //// //// //// xmlDocument.Save(fileStream); //how to dispose the created XmlDocument object. now how can i destroy the XmlDocument object? 回答1: First of all, you should not re-use streams like this. Do you really want to keep an external resource open for a long time? And will you seek the