xmlreader

Is XMLReader a SAX parser, a DOM parser, or neither?

牧云@^-^@ 提交于 2019-12-18 08:46:08
问题 I am testing various methods to read (possibly large, with very frequent reads) XML configuration files in PHP. No writing is ever needed. I have two successful implementations, one using SimpleXML (which I know is a DOM parser) and one using XMLReader . I know that a DOM reader must read the whole tree and therefore uses more memory. My tests reflect that. I also know that A SAX parser is an "event-based" parser that uses less memory because it reads each node from the stream without

XmlReader - I need to edit an element and produce a new one

不打扰是莪最后的温柔 提交于 2019-12-18 07:46:08
问题 I am overriding a method which has an XmlReader being passed in, I need to find a specific element, add an attribute and then either create a new XmlReader or just replace the existing one with the modified content. I am using C#4.0 I have investigated using XElement (Linq) but I can't seem to manipulate an existing element and add an attribute and value. I know that the XmlWriter has WriteAttributeString which would be fantastic but again I am not sure how it all fits together I would like

How to best detect encoding in XML file?

余生长醉 提交于 2019-12-18 05:54:36
问题 To load XML files with arbitrary encoding I have the following code: Encoding encoding; using (var reader = new XmlTextReader(filepath)) { reader.MoveToContent(); encoding = reader.Encoding; } var settings = new XmlReaderSettings { NameTable = new NameTable() }; var xmlns = new XmlNamespaceManager(settings.NameTable); var context = new XmlParserContext(null, xmlns, "", XmlSpace.Default, encoding); using (var reader = XmlReader.Create(filepath, settings, context)) { return XElement.Load(reader

Reading attribute values with XmlReader

☆樱花仙子☆ 提交于 2019-12-18 04:32:34
问题 I have an XML file that I'm trying to read from here, and have the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.IO; namespace XML { class Program { static void Main(string[] args) { XmlTextReader textReader = new XmlTextReader("secLendingXML.cfm.xml"); while (textReader.Read()) { switch (textReader.NodeType) { case XmlNodeType.Element: Console.WriteLine(textReader.Name); Console.WriteLine(textReader.Value)

How to create an XML file from a XmlReader?

不打扰是莪最后的温柔 提交于 2019-12-17 20:19:27
问题 How do you write an XML file from an System.Xml.XmlReader? I thought this would be a simple question but whenever I search I seem to be ending up with reading the file to a reader or writing node by node. The XmlReader object conveys xml that was stored in a database and just needs to come out of the database to a file. Is there any easy way to do this? SqlCommand dataCmd = new SqlCommand(sqlText, Conn); System.Xml.XmlReader dataReader = null; dataCmd.CommandTimeout = 60000; Conn.Open();

XmlReader breaks on UTF-8 BOM

佐手、 提交于 2019-12-17 20:09:04
问题 I have the following XML Parsing code in my application: public static XElement Parse(string xml, string xsdFilename) { var readerSettings = new XmlReaderSettings { ValidationType = ValidationType.Schema, Schemas = new XmlSchemaSet() }; readerSettings.Schemas.Add(null, xsdFilename); readerSettings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema; readerSettings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation; readerSettings.ValidationFlags |=

c# whitespaces issue with XmlReader

落爺英雄遲暮 提交于 2019-12-14 04:25:51
问题 I have a simple xml <data> <node1>value1</node1> <node2>value2</node2> </data> I'm using IXmlSerializable to read and write such xml with DTOs. The following code works just fine XmlReader reader; ... while( reader.Read() ){ Console.Write( reader.ReadElementContentAsString() ); } // outputs value1value2 However, if whitespaces in the xml are removed, i.e. <data> <node1>value1</node1><node2>value2</node2> </data> or I use XmlReaderSettings.IgnoreWhitespace = true; , the code outputs only

Parsing a large XML file to multiple output xmls, using XmlReader - getting every other element

久未见 提交于 2019-12-13 08:52:30
问题 I need to take a very large XML file and create multiple output xml files from what could be thousands of repeating nodes of the input file. There is no whitespace in the source file "AnimalBatch.xml" which looks like this: <?xml version="1.0" encoding="utf-8" ?><Animals><Animal id="1001"><Quantity>One</Quantity><Adjective>Red</Adjective><Name>Rooster</Name></Animal><Animal id="1002"><Quantity>Two</Quantity><Adjective>Stubborn</Adjective><Name>Donkeys</Name></Animal><Animal id="1003">

XML Parsing - Unable to retrieve value of node

淺唱寂寞╮ 提交于 2019-12-13 08:47:51
问题 I'm trying to determine why it is that I can not get the value of a node within my XML file. I'm using the following PHP code to parse my XML file... <?php error_reporting(E_ALL); ini_set( 'display_errors','1'); libxml_use_internal_errors(true); libxml_clear_errors(); // create the reader object $reader = new XMLReader(); // reader the XML file. $reader->open('test.xml'); // start reading the XML File. while($reader->read()) { // take action based on the kind of node returned switch($reader-

reading xml file with XmlReader reads only the first element

ⅰ亾dé卋堺 提交于 2019-12-13 08:27:34
问题 I'm having problems reading child elements with XmlReader. My xml file <?xml version="1.0" encoding="UTF-8"?> <WateringZones> <WateringZone> <Enabled>True</Enabled> <Name>Calle 1</Name> <Relay>1</Relay> <Monday>True</Monday> <Tuesday>True</Tuesday> <Wednesday>True</Wednesday> <Thursday>True</Thursday> <Friday>True</Friday> <Saturday>True</Saturday> <Sunday>False</Sunday> <WateringTurns> <WateringTurn> <Enabled>True</Enabled> <Name>Turno 1</Name> <Minutes>5</Minutes> </WateringTurn>