xmldocument

Why does XmlDocument.LoadXml throw System.Net.WebException?

放肆的年华 提交于 2019-12-06 19:50:29
问题 Why does System.Xml.XmlDocument.LoadXml method throw System.Net.WebException ? This is really mind boggling crazy, if MSDN was right, LoadXml should at most give me a System.Xml.XmlException . Yet I have weird exceptions like: The underlying connection was closed: The connection was closed unexpectedly. Dim document As New XmlDocument document.LoadXml("<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""><x></x>") MsgBox

How can I change an attribute value of a XML file in c#?

主宰稳场 提交于 2019-12-06 12:14:40
问题 I have a XML file(web.config) and I need to edit the value attribute of each tag, depend of the key name... this is an example of the XML file: <appSettings> <add key="A1" value="Hi" /> <add key="B1" value="Hello" /> </appSettings> I mean, How can I change the value "hi" & "hello" using the key attribute(A1 & B1) ?? Thanks alot 回答1: try this code, it works fine: XmlDocument doc = new XmlDocument(); doc.Load("Your.xml"); XmlNodeList elementList = doc.GetElementsByTagName("add"); for (int i = 0

Preserve xml formatting using XmlDocument

我的梦境 提交于 2019-12-06 10:21:39
问题 I am using XmlDocument to work with xml How do I save my "XmlDocument" with my current formatting? Current formatting: <?xml version="1.0" encoding="utf-8"?> <root> <element></element> </root> Code: XmlDocument testDoc = new XmlDocument(); testDoc.Load(@"C:\Test.xml"); **(do reading/writing using only XmlDocument methods)** testDoc.Save(@"C:\Test.xml"); There is a similar topic: XmlDocument class is removing formatting, c#, .NET The accepted answer is PreserveWhiteSpace = true, which in

How to Remove specific attributes in XMLDocument?

可紊 提交于 2019-12-06 09:47:19
In my C# codebase, I have a XMLDocument of the form: <A> <B> <C mlns='blabla' yz='blablaaa'> Hi </C> <D mlns='blabla' yz='blablaaa'> How </D> <E mlns='blabla' yz='blablaaa'> Are </E> <F mlns='blabla' yz='blablaaa'> You </F> </B> <B> <C mlns='blabla' yz='blablaaa'> I </C> <D mlns='blabla' yz='blablaaa'> am</D> <E mlns='blabla' yz='blablaaa'> fine</E> <F mlns='blabla' yz='blablaaa'> thanks</F> </B> </A> Using Linq-to-XML or otherwise, I want to remove the mlns and yz attributes for all the elements contained by element B . What is the best way to achieve it? Using LINQ to XML... public static

Force XmlDocument to save empty elements with an explicit closing tag

折月煮酒 提交于 2019-12-06 09:38:26
I have the following code: string PathName = "C:\\Users\\TestUser\\Documents\\Project"; string FileName = "settings.xml"; XmlDocument Settings = new XmlDocument(); Settings.Load(Path.Combine(PathName, FileName)); XmlNode KnowledgeNode = Settings.SelectSingleNode("/Config/Map/Knowledge"); XmlNode UsersNode = Settings.CreateNode(XmlNodeType.Element, "Users", null); XmlAttribute FileDirectory = Settings.CreateAttribute("FileDirectory"); FileDirectory.Value = UserSelectedFileDirectory; UsersNode.Attributes.Append(FileDirectory); KnowledgeNode.AppendChild(UsersNode); Settings.Save(Path.Combine

Library to generate .NET XmlDocument from HTML tag soup

一世执手 提交于 2019-12-06 05:36:02
I'm looking for a .NET library that can generate a clean Xml tree, ideally System.Xml.XmlDocument, from invalid HTML code. I.E. it should make the kind of best effort guesses, repairs, and substitutions browsers do when confronted with this situation, and generate a pretend XmlDocument. The library should also be well-maintained. :) I realize this is a lot (too much?) to ask, and I would appreciate any useful leads. There seem to be a fair number of implementations of this for Java, but I would rather not generate my own bindings. So far for .NET I have found http://www.majestic12.co.uk

How to load all the Xml files from a folder to an XmlDocument

我是研究僧i 提交于 2019-12-06 05:13:37
问题 With my below code, I am able to load one Xml file in XmlDocument xWorkload. XmlDocument xWorkload = new XmlDocument(); private void button1_Click(object sender, RoutedEventArgs e) { var outputxml = new StringBuilder(string.Empty); Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = "demo"; // Default file name dlg.DefaultExt = ".xml"; // Default file extension dlg.Filter = "Xml documents (.xml)|*.xml"; // Filter files by extension var result = dlg

How should I manage different incompatible formts of Xml based documents

人走茶凉 提交于 2019-12-06 03:24:33
问题 I have an application which saves documents (think word documents) in an Xml based format - Currently C# classes generated from xsd files are used for reading / writing the document format and all was well until recently when I had to make a change the format of the document. My concern is with backwards compatability as future versions of my application need to be able to read documents saved by all previous versions and ideally I also want older versions of my app to be able to gracefully

Access violation when using DocumentElement In XMLDocument

若如初见. 提交于 2019-12-05 22:47:15
问题 I always get an access violation when I try to use the DocumentElement of the XMLDocument . I create XMLDocument based on the existence of some file. Error message Project project1.exe raised exception class EAccessViolation with message 'Access violation at address 0047B152 in module 'project1.exe'.Read of Address B1D59357' My code unit XMLBase; interface uses SysUtils, xmldom, XMLIntf, XMLDoc, Forms; type TXMLbase = class private { Private declarations } public XMLDocument1: TXMLDocument;

XmlDocument SelectNodes(Xpath): Order of result

核能气质少年 提交于 2019-12-05 22:29:50
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"> <title>The Handmaid's Tale</title> </book> <book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6"> <title>Emma</title> </book> <book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3"> <title>Sense and Sensibility</title> </book> </bookstore> When I