ballhogjoni Posted October 3, 2007 Share Posted October 3, 2007 I want to extract certain parts of the following xml doc but I am using the script from php.net to do so. I only need to echo a few select tags. The php code parses and echoes all of the xml file, but I only want to echo the <creditcard></creditcard> and <issuer></issuer> information. How would I go abut making those changes to the php code? Sample of my XML file: <card> - <cid> - <![CDATA[ <ELEMENT>1033<ELEMENT> ]]> </cid> - <creditcard> - <![CDATA[ <ELEMENT>Advanta Platinum BusinessCard<ELEMENT> ]]> </creditcard> - <issuer> - <![CDATA[ <ELEMENT>Advanta<ELEMENT> ]]> </issuer> - <category> - <![CDATA[ <ELEMENT>Business<ELEMENT> ]]> </category> - <status> - <![CDATA[ <ELEMENT>Platinum<ELEMENT> ]]> </status> - <cardtype> - <![CDATA[ <ELEMENT>MasterCard<ELEMENT> ]]> </cardtype> - <introductoryrate> - <![CDATA[ <ELEMENT><ELEMENT> ]]> </introductoryrate> - <timeperiod> - <![CDATA[ <ELEMENT><ELEMENT> ]]> </timeperiod> - <appliedto> - <![CDATA[ <ELEMENT>Purchases, Balance Transfers<ELEMENT> ]]> </appliedto> </card> this is my php code <?php $file = "http://www.xxxxxxxxxxxxxxxx.com/partners/access/xml/xml.asp?uid=xxxxxxxxxxxxxxxxx"; $map_array = array( "BOLD" => "B", "EMPHASIS" => "I", "LITERAL" => "TT" ); function startElement($parser, $name, $attrs) { global $map_array; if (isset($map_array[$name])) { echo "<$map_array[$name]>"; } } function endElement($parser, $name) { global $map_array; if (isset($map_array[$name])) { echo "</$map_array[$name]>"; } } function characterData($parser, $data) { echo $data; } $xml_parser = xml_parser_create(); // use case-folding so we are sure to find the tag in $map_array xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); ?> Link to comment https://forums.phpfreaks.com/topic/71679-parse-xml-with-php-questions/ Share on other sites More sharing options...
ballhogjoni Posted October 3, 2007 Author Share Posted October 3, 2007 anybody? Link to comment https://forums.phpfreaks.com/topic/71679-parse-xml-with-php-questions/#findComment-360932 Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 I've never done anything like that, so I can't help you based on experience. There is this, though. http://www.php.net/manual/en/ref.xml.php Link to comment https://forums.phpfreaks.com/topic/71679-parse-xml-with-php-questions/#findComment-360937 Share on other sites More sharing options...
ballhogjoni Posted October 3, 2007 Author Share Posted October 3, 2007 Right...thx for the help, but thats where I got the PHP code in the first place. Link to comment https://forums.phpfreaks.com/topic/71679-parse-xml-with-php-questions/#findComment-361024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.