xmlreader

Validating a large XML file ~400MB in PHP

ぐ巨炮叔叔 提交于 2019-12-04 08:18:57
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 tested this with a file of about 60MB, but anything a lot larger (~400MB) causes something which is

Load just XPath search to XMLReader memory?

谁说我不能喝 提交于 2019-12-04 06:52:00
问题 Can i somehow do this? XMLReader is pull parser, so i expect from him to give me just data i search, but it loads whole document into memory and then gives me search from his memory. This code: $url = $this->buildUrl($name,$params); $xml = ''; $reader = new XMLReader(); $reader->open($url); $pathXML = ''; $dom = new DomDocument(); while($reader->read()) { if ($reader->nodeType == XMLREADER::ELEMENT && $reader->localName == 'OddsList'){ $xml = simplexml_import_dom($dom->importNode($reader-

XML with varying amount of child nodes for each parent node

眉间皱痕 提交于 2019-12-04 05:06:37
问题 So I have XML in the following format which I am reading from file 'test.xml' <XML> <Agent ID="ABC123"> <Property> <Code>XYZ</Code> <Name>Hotel 1</Name> </Property> <Property> <Code>237</Code> <Name>Hotel 2</Name> </Property> <Property> <Code>213</Code> <Name>Hotel 3</Name> </Property> </Agent> <Agent ID="DEF456"> <Property> <Code>333</Code> <Name>Hotel 4</Name> </Property> <Property> <Code>23423</Code> <Name>Hotel 5</Name> </Property> </Agent> <Agent ID="GHI789"> <Property> <Code>45345</Code

Prevent XmlTextReader from expanding entities

白昼怎懂夜的黑 提交于 2019-12-04 03:11:09
I am trying to read a XML document without expanding the entities, do some manipulations to it, and re-save it with the unexpanded entities as they were initially. When using the XDocument directly, it fails to load, throwing an exception tell me it has unexpanded entities: XDocument doc = XDocument.Load(file); // <--- Exception // ... do some manipulation to doc doc.Save(file2); Exception: Reference to undeclared entity 'entityname'. Then I tried to pass the XmlTextReader to the XDocument constructor, but the EntityHandling property does not have "no expand": XmlTextReader xmlReader = new

Reading xml with out using local/webserver

对着背影说爱祢 提交于 2019-12-03 23:05:19
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, I can imagine a few reasons why you want to develop an offline application : If you want an actual online application that might also work offline (with sync stuff in mind, or not) look at HTML5 : http://diveintohtml5.info

Error Serializing String in WebService call

余生长醉 提交于 2019-12-03 10:43:26
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 XML data. This quota may be increased by changing the MaxStringContentLength property on the

Parsing through XML elements in XmlReader

人盡茶涼 提交于 2019-12-03 09:02:36
I'm building an application that needs to run through an XML feed but I'm having a little trouble with getting certain elements. I'm using the Twitter feed and want to run through all the <item> elements. I can connect fine and get the content from the feed but I can't figure out how to select only the item elements when I'm loopuing through reader.Read(); . Thanks for your help! The easiest way to do that is to use XPath. Example to follow. string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?> <rss version=""2.0""> <channel> <title>Twitter public timeline</title> <link>http://twitter.com

How to get an attribute from an XMLReader

大兔子大兔子 提交于 2019-12-03 03:51:26
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 attribute, not a property. However, there isn't a getAttribute() method for XMLReader . So my question is, how

Performance: XmlReader or LINQ to XML

非 Y 不嫁゛ 提交于 2019-12-03 00:11:30
I have a 150 MB XML file which is used as DB in my project. Currently I'm using XmlReader to read content from it. I want to know if it is better to use XmlReader or LINQ to XML for this scenario. Note that I'm searching for an item in this XML and display search result, so it can take a long time or just a moment. Tebari If you want performance use XMLReader. It doesn't read the whole file and build the DOM tree in memory. It instead, reads the file from disk and gives you back each node it finds on the way. With a quick google search I found a performance comparison of XMLReader, LinqToXML

XMLReader - How to handle undeclared namespace

吃可爱长大的小学妹 提交于 2019-12-02 20:45:31
问题 Merged with How to read an XML file with an undefined namespace with XMLReader?. I'm reading a large ~300Mb gzipped XML file with XMLReader that get's automatically dumped to my server nightly (archaic, I know..) It is malformed ie, it has an undefined namespace and it's throwing an error ErrorException [ Warning ]: XMLReader::read() namespace error : Namespace prefix xsi for AttrName on NodeName is not defined What is the best way to deal with this? It seems impractical to uncompress, load