xmlreader

Performance: XmlReader or LINQ to XML

时间秒杀一切 提交于 2019-12-31 17:39:15
问题 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. 回答1: 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

How to parse XML with unescaped ampersand

五迷三道 提交于 2019-12-31 07:00:10
问题 I have to read large (about 200MB) XML file, I'am using xmlreader with PHP. There is node URL with unescaped ampersand in it. Parsing always stops on first url NODE. I'm using encoding windows-1250 same as is specified in xml tag of XML file. Iam getting error: parser error : EntityRef: expecting ';' in Is it possible to parse an XML with & in value of NODE ? Thank you for any tips, I can share a code if you need. 回答1: Is it possible to parse an XML with & in value of NODE ? No, that means

PHP xmlreader to array

╄→гoц情女王★ 提交于 2019-12-31 04:40:46
问题 The following test function reads an XML file with PHP's xmlreader and returns a 2 dimensional array of 3 values ("id" = key). How can you edit the code so that the username key and value is returned in the array also? (shown at the end) ini_set('always_populate_raw_post_data', 'on'); function test() { $request = $HTTP_RAW_POST_DATA; error_reporting(E_ERROR | E_WARNING | E_PARSE); $url = "http://site.xml"; $reader = new XMLReader(); $reader->open($url);; $var = array(); $i = 0; $limit = 3;

PHP XMLReader, get the version and encoding

余生颓废 提交于 2019-12-31 02:21:06
问题 I'm currently rewriting a PHP class that tried to split an XML file into smaller chunks to use XMLReader and XMLWriter instead of the current basic filesystem and regex approach. However, I can't figure out how to get the version, encoding and standalone flags from the XML preamble. The start of my test XML file looks like this: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE fakedoctype SYSTEM "fake_doc_type.dtd"> <!-- This is a comment, it's here to try and get the parser to break in some

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

≯℡__Kan透↙ 提交于 2019-12-30 05:29:04
问题 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

How do I Skip XML Reader by reading empty attribute node?

眉间皱痕 提交于 2019-12-25 02:28:39
问题 I want to skip empty id parent node and move to not empty id parent node in this kind of XML document.Currently my program using XmlTextReader to read and process this XML. But sometime record id can be empty and that time I want to skip this record parent node and reader should move to next node without reading that empty id parent node. Guys do you have any idea to do that ? Please help me !!! `<record id=""> <record><data></data></record> <record><data></data></record> </record> <record id

How to create a XML with a Specific Encoding using XSLT and XMLWRITER

☆樱花仙子☆ 提交于 2019-12-24 16:58:07
问题 I am trying to apply a XSL style sheet on a source xml and write the output to a target xml file. The xsl removes the xml comments present inside the source xml. The target xml file has UTF-16 encoding in the header. But still i want the output xml to be utf-8 encoding. The code i used is XmlWriterSettings xwrSettings = new XmlWriterSettings(); **xwrSettings.Encoding = Encoding.UTF8;** XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("sample.xsl"); StringBuilder sb = new

XMLReader encoding error

心不动则不痛 提交于 2019-12-24 16:35:13
问题 I have a PHP script which is trying to parse a huge XML file. To do this I'm using the XMLReader library. During the parsing, I have this encoding error: Input is not proper UTF-8, indicate encoding ! Bytes: 0xA0 0x32 0x36 0x30 I would like to know if they are a way to skip records with bad characters. Thanks! 回答1: First of all, make sure that your XML file is indeed UTF-8 encoded. If not specify the encoding as the second parameter to XMLReader::open(). If the encoding error is due a real

How to enable XMLReader in PHP without reconfiguring PHP?

感情迁移 提交于 2019-12-24 14:16:14
问题 My PHP info has this: Configure Command : '--with-libxml-dir=/usr' '--enable-xml' '--disable-xmlreader' '--disable-xmlwriter' i.e. my xmlwriter & xmlreader have not been enabled during installation. libxml libXML support active libXML Compiled Version 2.7.8 libXML Loaded Version 20708 libXML streams enabled from php.net manual for XMLReader Runtime Configuration This extension has no configuration directives defined in php.ini . How do I enable XMLReader? / Do I have have to compile my PHP

Should I output cache my control that looks up twitter RSS onload?

ε祈祈猫儿з 提交于 2019-12-24 12:28:26
问题 I have a user control that is featured on several pages of a heavily hit site. Some of these pages include our blog sidebar, our forum sidebar, and smack right in the middle of our home page. That means this control is rendered a lot. The control it meant to read in a twitter RSS feed for a specific account and write out the last 2 tweets. Below is the majority of my Page_Load for the control. I have it in a try {} catch because it seems that on production the site is unable to load the XML