XML_Parse_into_struct function...

From: Date: Mon, 10 May 1999 10:06:15 +0000
Subject: XML_Parse_into_struct function...
Groups: php.dev 
Request: Send a blank email to php-dev+get-5470@lists.php.net to get a copy of this message
hi, just implemented this neat function which will: test.xml: <A test="hallo"> hallo <B> PHP </B> welcome </A> php-snippet: xml_parse_into_struct($xml_parser,$data,&$struct,&$index) create 2 very handy structures for u! data: array(4) { int(0) array(5) { string(3) "tag" string(1) "A" // tag-name string(4) "type" string(4) "open" // tag got opened (expect a close-tag later) string(5) "level" int(1) // tag-level string(10) "attributes" // attributes array(1) { string(4) "TEST" string(5) "hallo" } string(5) "value" // value string(7) " hallo " } int(1) array(4) { string(3) "tag" string(1) "B" string(4) "type" string(8) "complete" // complete tag - no close tag to follow string(5) "level" int(2) string(5) "value" string(5) " PHP " } int(2) array(4) { string(3) "tag" string(1) "A" string(5) "value" string(9) " welcome " string(4) "type" string(5) "cdata" // additional character data for tag "A" string(5) "level" int(1) } int(3) array(3) { string(3) "tag" string(1) "A" string(4) "type" string(5) "close" string(5) "level" int(1) } } index: gives you a handy index for structure "data" array(2) { string(1) "A" array(3) { int(0) int(0) // tag A is found at positione data[0] int(1) int(2) // tag A is found at positione data[2] int(2) int(3) // tag A is found at positione data[3] } string(1) "B" array(1) { int(0) int(1) // tag b is found at positione data[1] } } there are 2 new options (only valid for parse_into_struct) ---------------------------------------------------------- xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1); which will force parse_into_struct NOT to create entries for whitespace between tags! if you don't specify this you will get a lot of empty(or just one CR) "cdata" elements in your result array.... xml_parser_set_option($xml_parser, XML_OPTION_SKIP_TAGSTART, 1); my problem is that i do full text indexing on my xml-documents and i always prefix each tag-name with an "x" which means <TITLE> becomes <xTITLE> - that way i will not find every document if i search for TITLE. (this way i can "hide" my xml-tags from oracle-context free-text-engine..... tc Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!" Digital Collections Phone +49 40 235350 Fax +49 40 23535180 Hammerbrookstr. 93 20097 Hamburg / Germany -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#5470) next »