xmlreader

Reading XML from Stream

心已入冬 提交于 2019-12-01 16:32:07
I'm working with ASP.NET, and am importing an XML file from a form. Right now I convert that into a Stream : Stream inputStream = XmlFileUploadControl.PostedFile.InputStream; because I may need this version later. I'd like to first check to make make sure that the XML file has the correct format, and, if it is, then display some information: if (CorrectFileFormat(inputStream)) { DisplayLicenseInfo(inputStream); } else { StatusLabel.Text = "Selected file is not a LicensingDiag XML file"; } The CorrectFileFormat() method: protected Boolean CorrectFileFormat(Stream inputStream) { XmlReader reader

Serialize and Deserialize XML using dot.net c#

老子叫甜甜 提交于 2019-12-01 15:10:34
I have spent the last few hours putting togeather the following code after reading much that seems out of date or that does'nt quite seem to work. If its any help to anybody here is the final working code. Free free to comment if it can be improved :-) public class SerializationHelper<T> { #region static string SerializeObject( T obj, Encoding encoding ) /// <summary> /// Serialize an [object] to an Xml String. /// </summary> /// <typeparam name="T">Object Type to Serialize</typeparam> /// <param name="obj">Object Type to Serialize</param> /// <param name="encoding">System.Text.Encoding Type<

How to read XML via c# such as <Mode Name=“text”>

末鹿安然 提交于 2019-12-01 14:26:09
I want to know how to get attribute "text" via c#? Example xml: <?xml version="1.0" encoding="utf-8" ?> <Model Name="modelname"> <Mode Name="text"> <Class>Class1</Class> </Mode> </Model> I try to parse this xml by using XMLReader(example from msdn) : while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: Console.Write("<" + reader.Name+""); Console.WriteLine(str); if (reader.Name =="Mode") { namemode = true; } if (namemode) { if (reader.Name == element) { elementExists = true; } } // Console.WriteLine(">"); break; case XmlNodeType.Text: Console.WriteLine(reader.Value); if

porting to Android: why am I getting “Can't create default XMLReader; is system property org.xml.sax.driver set?”?

痞子三分冷 提交于 2019-12-01 05:31:27
I am porting some Java code that worked fine on my desktop to Android. I have the following code segment: import org.xml.sax.InputSource; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; // ... XMLReader p = XMLReaderFactory.createXMLReader(); At the last line I get the following exception: Can't create default XMLReader; is system property org.xml.sax.driver set? When I was testing the code on desktop, it was working fine. Why am I getting this exception on Android and how can I fix it? Thx! I just ran into the same issue while porting some code to Android. I found

PHP XMLReader read , edit Node , write XMLWriter

徘徊边缘 提交于 2019-12-01 04:13:08
问题 I have an XML file which is very very large (millions of records). Due to speed and memory constraints I plan to use XMLReader / XMLWriter . I need to read the file, getting one record, change its attribute, and finally save XML again. For testing I created an XML file and write some records into it using these lines: $doc = new XMLWriter(); $doc->openURI($xmlFile); $doc->startDocument('1.0','UTF-8'); $doc->setIndent(4); $doc->startElement('DBOS'); for($r=0;$r<10; $r++){ $doc->startElement(

xmlreader newline \\n instead of \\r\\n

安稳与你 提交于 2019-12-01 03:10:26
When I use XmlReader.ReadOuterXml(), elements are separated by \n instead of \r\n. So, for example, if I have XmlDocument representatino of <A> <B> </B> </A> I get <A>\n<B>\n</B>\n</A> Is there an option to specify newline character? XmlWriterSettings has it but XmlReader doesn't seem to have this. Here is my code to read xml. Note that XmlWriterSettings by default has NewLineHandling = Replace XmlDocument xmlDocument = <Generate some XmlDocument> XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; // Use a memory stream because it accepts UTF8 characters. If we use a

Read a namespaced attribute from a SimpleXmlElement (imported from XMLReader)

喜夏-厌秋 提交于 2019-12-01 02:04:49
问题 I'm trying to read a large xml file (about 40 MB), and use this data for update the db of my application. It seems i've found a good compromise in terms of elapsed time/memory using XMLReader and simplexml_import_dom() but i can't get the value of attributes with colon in their name... for example <g:attr_name> . If i simply use $reader->read() function for each "product" node i can retrive the value as $reader->value, but if i expand() the node and copy it with $doc->importNode this

xmlreader newline \n instead of \r\n

我的未来我决定 提交于 2019-11-30 23:18:59
问题 When I use XmlReader.ReadOuterXml(), elements are separated by \n instead of \r\n. So, for example, if I have XmlDocument representatino of <A> <B> </B> </A> I get <A>\n<B>\n</B>\n</A> Is there an option to specify newline character? XmlWriterSettings has it but XmlReader doesn't seem to have this. Here is my code to read xml. Note that XmlWriterSettings by default has NewLineHandling = Replace XmlDocument xmlDocument = <Generate some XmlDocument> XmlWriterSettings settings = new

How to use XMLReader/DOMDocument with large XML file and prevent 500 error

青春壹個敷衍的年華 提交于 2019-11-30 17:04:18
I have an XML file that is approximately 12mb which has about 16000 product's. I need to process it into a database; however, at about 6000 rows it dies with a 500 error. I'm using the Kohana framework (version 3) just in case that has anything to do with it. Here's my code that I have inside the controller: $xml = new XMLReader(); $xml->open("path/to/file.xml"); $doc = new DOMDocument; // Skip ahead to the first <product> while ($xml->read() && $xml->name !== 'product'); // Loop through <product>'s while ($xml->name == 'product') { $node = simplexml_import_dom($doc->importNode($xml->expand(),

Problem reading files greater than 1GB with XMLReader

二次信任 提交于 2019-11-30 08:46:47
问题 Is there a maximum file size the XMLReader can handle? I'm trying to process an XML feed about 3GB large. There are certainly no PHP errors as the script runs fine and successfully loads to the database after it's been run. The script also runs fine with smaller test feeds - 1GB and below. However, when processing larger feeds the script stops reading the XML File after about 1GB and continues running the rest of the script. Has anybody experienced a similar problem? and if so how did you