Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Using PHP to parse specific XML tag content?

From: Mechphisto <mechphisto@-----.--->
To: NULL
Date: 12/2/2008 8:49:00 AM
On Dec 2, 10:07=A0am, Mechphisto <mechphi...@gmail.com> wrote:
> On Dec 2, 9:14=A0am, Mechphisto <mechphi...@gmail.com> wrote:
> [..snip all..]
> Based on the fact the above works, it's just not doing exactly what I
> want, I tried the following adjustments to the PHP.
> Logically, I don't see any reason why it's not working, but it's
> simply not displaying anything on the echo's.
> Any ideas?
>
> <?php
> $file =3D "xml_test.xml";
> function startTag($parser, $data){
> =A0 =A0 =A0 =A0 global $msg1;
> =A0 =A0 =A0 =A0 global $msg2;
> =A0 =A0 =A0 =A0 global $current;
> =A0 =A0 =A0 =A0 $current =3D $data;
> =A0 =A0 =A0 =A0 if ($current =3D=3D "message1") {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $msg1 .=3D "<b>";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return $msg1;
> =A0 =A0 =A0 =A0 } elseif ($current =3D=3D "message2") {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $msg2 .=3D "<em>";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return $msg2;
> =A0 =A0 =A0 =A0 }}
>
> function endTag($parser, $data){
> =A0 =A0 =A0 =A0 global $msg1;
> =A0 =A0 =A0 =A0 global $msg2;
> =A0 =A0 =A0 =A0 if ($data =3D=3D "message1") {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $msg1 .=3D "</b>";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return $msg1;
> =A0 =A0 =A0 =A0 } elseif ($data =3D=3D "message2") {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $msg2 .=3D "</em>";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return $msg2;
> =A0 =A0 =A0 =A0 }}
>
> function contents($parser, $data){
> =A0 =A0 =A0 =A0 global $msg1;
> =A0 =A0 =A0 =A0 global $msg2;
> =A0 =A0 =A0 =A0 global $current;
> =A0 =A0 =A0 =A0 if ($current =3D=3D "message1") {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $msg1 .=3D $data;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return $msg1;
> =A0 =A0 =A0 =A0 } elseif ($current =3D=3D "message2") {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $msg2 .=3D $data;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return $msg2;
> =A0 =A0 =A0 =A0 }}
>
> $xml_parser =3D xml_parser_create();
> xml_set_element_handler($xml_parser, "startTag", "endTag");
> xml_set_character_data_handler($xml_parser, "contents");
> $fp =3D fopen($file, "r");
> $data =3D fread($fp, 80000);
> if(!(xml_parse($xml_parser, $data, feof($fp)))){
> =A0 =A0 =A0 =A0 die("Error on line " . xml_get_current_line_number($xml_p=
arser));}
>
> xml_parser_free($xml_parser);
> fclose($fp);
>
> echo $msg1;
> echo $msg2;
> ?>

Oh holy sheesh!
I saw somewhere something about the parser converting tags to
uppercase, so I changed all the tags to uppercase in the PHP and in
the XML file, and bammo! It all works fine now.
Crazy, annoying... grrr.



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