xmlreader

Change the encoding to UTF-8 on a stream (MemoryMappedViewStream)

江枫思渺然 提交于 2019-12-06 03:55:37
I am using the code below to read a ~2.5Gb Xml file as fast as I can (thanks to MemoryMappedFile). However, I am getting the following exception: " '.', hexadecimal value 0x00, is an invalid character. Line 9778, position 73249406. ". I beleive it is due to some encoding problem. How do I make sure that the MemoryMappedViewStream reads the file using UTF-8? static void Main(string[] args) { using (var file = MemoryMappedFile.CreateFromFile(@"d:\temp\temp.xml", FileMode.Open, "MyMemMapFile")) { using (MemoryMappedViewStream stream = file.CreateViewStream()) { Read(stream); } } } static void

Validating a large XML file ~400MB in PHP

走远了吗. 提交于 2019-12-06 03:17:58
问题 I have a large XML file (around 400MB) that I need to ensure is well-formed before I start processing it. First thing I tried was something similar to below, which is great as I can find out if XML is not well formed and which parts of XML are 'bad' $doc = simplexml_load_string($xmlstr); if (!$doc) { $errors = libxml_get_errors(); foreach ($errors as $error) { echo display_xml_error($error); } libxml_clear_errors(); } Also tried... $doc->load( $tempFileName, LIBXML_DTDLOAD|LIBXML_DTDVALID ) I

Is there an XmlReader equivalent for HTML in .Net?

断了今生、忘了曾经 提交于 2019-12-05 19:45:27
I've used HtmlAgilityPack in the past to parse HTML in .Net but I don't like the fact that it only uses a DOM model. On large documents and/or those with heavy levels of nesting it is possible to hit stack overflow or out of memory exceptions. Also in general a DOM based parsing model uses significantly more memory than a streaming based approach, typically because the process that wants to consume the HTML may only need a few elements to be available at a time. Does anyone know of a decent HTML parser for .Net that allows you to parse HTML in a manner similar to the XmlReader class? i.e. in a

Reading xml with out using local/webserver

岁酱吖の 提交于 2019-12-05 10:39:30
问题 I am new to javascript.I am trying to read an xml file from application folder, which is located in the hard disk. "Cross origin requests are only supported for HTTP." this is the error that is being thrown. If I try to access the same xml file via local server/web server it works fine. Since i am trying to develop offline application. How do i make it work locally. Thanks, 回答1: I can imagine a few reasons why you want to develop an offline application : If you want an actual online

LINQ to XML vs. XmlReader

江枫思渺然 提交于 2019-12-05 09:39:51
In my Silverlight application I'm using mostly XmlReader but I'm playing with idea to replace XmlReader implementation with LINQ to XML. What are pros and cons between LINQ to XML and XmlReader in Silverlight? PROs of Linq to XML Query XML documents with the same LINQ syntax your used to Uses the same X objects that you're used to working with (XElement, etc.) PROs of using XmlReader Finer grain control over the query syntax (XPath rather than LINQ) ...personally, I switched to LINQ to XML when it was first introduced and never looked back. Haven't noticed any significant performance

Why filestream not closed by xmlreader

China☆狼群 提交于 2019-12-05 05:40:46
So I am using the filestream inside xmlreader using (XmlReader reader = XmlReader.Create(new FileStream(archivePath, FileMode.Open), readerSettings)) { reader.close() } However, the file feed into the xmlreader still in the lock state after the using scope, weird, I thougt the xmlreader is going to close the filestream for me, is it not? Thanks for help. Have you tried this? using(var stream = new FileStream(archivePath, FileMode.Open)) using(var reader = XmlReader.Create(stream, readerSettings)) { } I couldn't find anything in the documentation that explicitly stated that the XmlReader would

How to get value from a specific child element in XML using XmlReader?

流过昼夜 提交于 2019-12-05 03:56:45
Here's the XML string. <?xml version="1.0" encoding="utf-16"?> <questionresponses> <question id="dd7e3bce-57ee-497a-afe8-e3d8d25e2671"> <text>Question 1?</text> <response>abcdefg</response> <correctresponse>123</correctresponse> </question> <question id="efc43b1d-048f-4ba9-9cc0-1cc09a7eeaf2"> <text>Question 2?</text> <response>12345678</response> <correctresponse>123</correctresponse> </question> </questionresponses> So how could I get value of <response> element by given question Id? Say, if I give id value = "dd7e3bce-57ee-497a-afe8-e3d8d25e2671", I'd like to have string value abcdefg

How to update this xml file with PHP XML reader & writer?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 20:00:18
I have the following sitemap XML which contains a list of URLs to be submitted for search engines. I took this example code from another SO answer. // Init XMLWriter $writer = new XMLWriter(); $writer->openURI(APPLICATION_PATH . '/sitemap.xml'); // document head $writer->startDocument('1.0', 'UTF-8'); $writer->setIndent(4); $writer->startElement('urlset'); $writer->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); // Write something // this will write: <url><loc>some url here; SO not allowed me</loc></url> $writer->startElement('url'); $writer->writeElement('loc', 'some

Error Serializing String in WebService call

☆樱花仙子☆ 提交于 2019-12-04 16:46:48
问题 This morning I ran into an issue with returning back a text string as result from a Web Service call. the Error I was getting is below ************** Exception Text ************** System.ServiceModel.CommunicationException: Error in deserializing body of reply message for operation 'GetFilingTreeXML'. ---> System.InvalidOperationException: There is an error in XML document (1, 9201). ---> System.Xml.XmlException: The maximum string content length quota (8192) has been exceeded while reading

How to get an attribute from an XMLReader

做~自己de王妃 提交于 2019-12-04 09:41:25
问题 I have some HTML that I'm converting to a Spanned using Html.fromHtml(...) , and I have a custom tag that I'm using in it: <customtag id="1234"> So I've implemented a TagHandler to handle this custom tag, like so: public void handleTag( boolean opening, String tag, Editable output, XMLReader xmlReader ) { if ( tag.equalsIgnoreCase( "customtag" ) ) { String id = xmlReader.getProperty( "id" ).toString(); } } In this case I get a SAX exception, as I believe the "id" field is actually an