xmlreader

How to read an XML File

感情迁移 提交于 2019-11-26 22:11:40
问题 I have a VB.net program. I'm attempting to use XMLReader to read a .xml file. I want to break the XML File up to organize it into different "Sections" In this example "FormTitle" and "ButtonTitle" . I would like to grab the <Text> data from FormTitle and display it as the Form "text" and take the <Text> in "ButtonTitle" and have it display in the button text. Here is my XML File: <?xml version="1.0" encoding="utf-8"?> <!--XML Database.--> <FormTitle> <Text>Form Test</Text> </FormTitle>

XmlReader - problem reading xml file with no newlines

拥有回忆 提交于 2019-11-26 21:51:52
问题 When I use XmlReader to parse an XML file, I get different results depending on whether the XML file is properly formatted (i.e. with newlines) or not. This is the code I'm using: XmlReader reader = new XmlTextReader(xmlfile); reader.MoveToContent(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "entry") { Console.WriteLine(reader.ReadElementContentAsString()); } break; } } And the XML content I've been using is: <xport><meta><columns>5<

DTD prohibited in xml document exception

微笑、不失礼 提交于 2019-11-26 16:20:13
问题 I'm getting this error when trying to parse through an XML document in a C# application: "For security reasons DTD is prohibited in this XML document. To enable DTD processing set the ProhibitDtd property on XmlReaderSettings to false and pass the settings into XmlReader.Create method." For reference, the exception occurred at the second line of the following code: using (XmlReader reader = XmlReader.Create(uri)) { reader.MoveToContent(); //here while (reader.Read()) //(code to parse xml doc

Appending an existing XML file with XmlWriter

亡梦爱人 提交于 2019-11-26 15:31:30
I've used the following code to create an XML file: XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; xmlWriterSettings.NewLineOnAttributes = true; using (XmlWriter xmlWriter = XmlWriter.Create("Test.xml", xmlWriterSettings)) { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("School"); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); } I need to insert nodes dynamically creating the following structure: <?xml version="1.0" encoding="utf-8"?> <School /> <Student> <FirstName>David</FirstName> <LastName>Smith<

XmlReader - Self-closing element does not fire a EndElement event?

孤人 提交于 2019-11-26 14:33:57
问题 I am using XmlReader in .NET to parse an XML file using a loop: while (xml.Read()) { switch xml.NodeType { case XmlNodeType.Element: //Do something case XmlNodeType.Text: //Do something case XmlNodeType.EndElement: //Do something } } I was wondering if it was normal that the following XML code does not produce some EndElement nodes? Please note the missing space before the /> but I don't think that's the problem. <date month="November" year="2001"/> <zone name="xml"/> Is there a different

Why “Data at the root level is invalid. Line 1, position 1.” for XML Document?

血红的双手。 提交于 2019-11-26 14:20:14
问题 I am using a third-party DLL which transmits an XML document over the internet. Why would the DLL be throwing the following exception? Data at the root level is invalid. Line 1, position 1. (see below for full exception text.) Here are the first few lines of the XML Document: <?xml version="1.0" encoding="utf-8"?> <REQUEST> <HEADER> <REQUESTID>8a5f6d56-d56d-4b7b-b7bf-afcf89cd970d</REQUESTID> <MESSAGETYPE>101</MESSAGETYPE> <MESSAGEVERSION>3.0.2</MESSAGEVERSION> Exception: System

Deciding on when to use XmlDocument vs XmlReader

徘徊边缘 提交于 2019-11-26 12:19:51
问题 I\'m optimizing a custom object -> XML serialization utility, and it\'s all done and working and that\'s not the issue. It worked by loading a file into an XmlDocument object, then recursively going through all the child nodes. I figured that perhaps using XmlReader instead of having XmlDocument loading/parsing the entire thing would be faster, so I implemented that version as well. The algorithms are exactly the same, I use a wrapper class to abstract the functionality of dealing with an

What is the best way to parse (big) XML in C# Code?

江枫思渺然 提交于 2019-11-26 11:12:25
I'm writing a GIS client tool in C# to retrieve "features" in a GML-based XML schema (sample below) from a server. Extracts are limited to 100,000 features. I guestimate that the largest extract.xml might get up around 150 megabytes, so obviously DOM parsers are out I've been trying to decide between XmlSerializer and XSD.EXE generated bindings --OR-- XmlReader and a hand-crafted object graph. Or maybe there's a better way which I haven't considered yet? Like XLINQ, or ???? Please can anybody guide me? Especially with regards to the memory efficiency of any given approach. If not I'll have to

Appending an existing XML file with XmlWriter

霸气de小男生 提交于 2019-11-26 04:00:04
问题 I\'ve used the following code to create an XML file: XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; xmlWriterSettings.NewLineOnAttributes = true; using (XmlWriter xmlWriter = XmlWriter.Create(\"Test.xml\", xmlWriterSettings)) { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement(\"School\"); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); } I need to insert nodes dynamically creating the following structure

What is the best way to parse (big) XML in C# Code?

≡放荡痞女 提交于 2019-11-26 02:18:46
问题 I\'m writing a GIS client tool in C# to retrieve \"features\" in a GML-based XML schema (sample below) from a server. Extracts are limited to 100,000 features. I guestimate that the largest extract.xml might get up around 150 megabytes, so obviously DOM parsers are out I\'ve been trying to decide between XmlSerializer and XSD.EXE generated bindings --OR-- XmlReader and a hand-crafted object graph. Or maybe there\'s a better way which I haven\'t considered yet? Like XLINQ, or ???? Please can