Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Using PHP to parse specific XML tag content?

From: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= <alvaroNOSPAMTHANKS@----------.--->
To: NULL
Date: 12/2/2008 5:01:00 PM
Mechphisto escribió:
> I'm trying to write a PHP script that will grab the info from an XML
> file, and parse and sort the data into their own variables.
> Can someone point me a direction for information?
[...]
> $xml_parser = xml_parser_create();
> xml_set_element_handler($xml_parser, "startTag", "endTag");
> xml_set_character_data_handler($xml_parser, "contents");

I wrote an XML parser a few years ago and it's not something I'd like to 
repeat. While parsing you must keep track of where you are (inside a 
tag? which tag?) and you have to deal with stuff like "What if 
contents() doesn't return the whole contents because fread() stopped in 
the middle?". There're many tools nowadays that avoid you the boring 
internals.

You can use any of the built-in libraries:

http://es.php.net/manual/en/refs.xml.php

Some people love SimpleXML. I've found XMLReader quite usable. There's 
even a user note with the code you want to write:

http://es.php.net/manual/en/class.xmlreader.php#87288

Or you can use third-party code. I specially enjoy phpQuery:

http://code.google.com/p/phpquery/



-- 
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent