Thread: [phpXML] Need example for 'context'
Brought to you by:
bs_php,
nigelswinson
From: <tom...@di...> - 2001-10-08 14:23:02
|
Hello all, I need a very specific example for the use of 'context' in the original distro examples. What are inputs that show a highlighted result ? "XPath Expression:" "XPath Context:" E.g. what input for each field in the form testsuite.php (processing the 'government.xml' file) Whaterver combination I use (just one example) Example (my entries) XPath Expression: //prename XPath Context: /government/person - I get no result highlighted Many thanks, Tom -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |
From: <tom...@di...> - 2001-10-08 17:01:58
|
Nigel, I'e just tested your supposition - voila ;-) Using for example: Expression: "/surname" Context: "/government[1]/person[3]" Provides a working answer. Though I was a bit surprised that, since there was only a single node for 'government', "context" still required the "/government[1]" syntax. Many thanks for the hint - I never would have guessed that the [1] was needed to define a singular node Tom At 03:58 PM 7/4/01 +0000, Ni...@Sw... wrote: >Try using a context of /government[1] > >The context (I think) has to be a COMPLETE address. Not just an XPath >address that evaluates to only one node. > >I haven't tested this, but I think this is right. > >Nigel > >----- Original Message ----- >From: <tom...@di...> >To: <us...@li...> >Sent: Wednesday, July 04, 2001 2:29 PM >Subject: [phpXML] Need example for 'context' > > > > Hello all, > > > > I need a very specific example for the use of 'context' in the original > > distro examples. > > > > What are inputs that show a highlighted result ? > > "XPath Expression:" > > "XPath Context:" > > > > E.g. what input for each field in the form testsuite.php (processing the > > 'government.xml' file) > > > > Whaterver combination I use (just one example) > > Example (my entries) > > XPath Expression: file://prename > > XPath Context: /government/person > > - I get no result highlighted > > > > Many thanks, > > Tom > > > > > > -- > > This message has been sent through the <phpXML/> user discussion list. > To unsubscribe, please visit > https://sslsites.de/mailinglisten/user/us...@li.../ > > > > >-- >This message has been sent through the <phpXML/> user discussion list. To >unsubscribe, please visit >https://sslsites.de/mailinglisten/user/us...@li.../ -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |
From: <ph...@pe...> - 2001-10-08 14:30:54
|
On Wednesday 04 July 2001 20:42, you wrote: > > Though I was a bit surprised that, since there was only a single node for > 'government', "context" still required the "/government[1]" syntax. > > Many thanks for the hint - I never would have guessed that the [1] was > needed to define a singular node > > Tom it's an array. a bit like seats in a theatre or train: you can't say 'tell me who's sitting in seat', you have to define which seat, even if only one seat is occupied - or even if no seat is occupied. -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |
From: Nigel S. on b. of <ma...@po...> - 2001-10-10 22:09:27
|
Hello all. let's make some example: test.xml: <article> <header> header of article </header> <body> <para> paragraph ... </para> <emp> emphasized text </emp> <para> whatever </para> </body> </article> and php code: <?php include './xml/xml.php'; $xmlfile = new XML ('test.xml'); $body = $xmlfile -> evaluate('/article/body/*'); foreach ($body as $body_elem) { print $body_elem.'<br/>'; } ?> Result is: /article[1]/body[1]/para[1] /article[1]/body[1]/para[2] /article[1]/body[1]/emp[1] I would like to see result like this: /article[1]/body[1]/para[1] /article[1]/body[1]/emp[1] /article[1]/body[1]/para[2] . Can you suggest a solution that might solve this problem. I need to obtain paths to nodes in the same order as in xml. waiting for help. :) Maciej Kus -------------------- [POLBOX - REKLAMA] ------------------------ Sprawd swoje bezpieczeñstwo w Sieci Zabezpiecz siê ! www.symantec.com/region/pl/product/nis2001.html ---------------------------------------------------------------- -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |
From: <mf...@mr...> - 2001-10-08 16:02:20
|
Hello Maciej Kus, > . Can you suggest a solution that might solve this problem. > I need to obtain paths to nodes in the same order as in xml. > waiting for help. :) > > Maciej Kus Use the cheap built in sequential XML parser functions of php like xml_parser_create - create an XML parser xml_set_element_handler - set up start and end element handlers xml_set_character_data_handler - set up character data handler xml_parse - start parsing an XML document ... and so on (see the php documentation searching with keyword "XML parser functions" ). They are exactly designed for sequential reading the xml file whereas the <phpxml/> or the xml dom are needed if you want to be independent from the sequential structure of the xml data. -- Marko Faldix M+R infosysteme Hubert-Wienen-Str. 24 52070 Aachen Tel.: 0241-93878-16 Fax.:0241-875095 E-Mail: mf...@mr... -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |
From: <wl...@bl...> - 2001-10-08 18:35:00
Attachments:
xml.inc.zip
|
By Using <!CDATA[ any <tagged> text ]] i've modified my xml.php version to detect weather there are html tags or other text that might ruin an xml document structure. modified xml.php included.. // From my previous email to the list Here's a little snippit from the xml.php I modified to accomodate the lack of CDATA creation in a node that contains characters that would otherwise make an XML document invalid. What do you think? Can you improve it? -When I call $xmlobj->get_file(); it will go through the $xmlobj->nodes array and format the XML document. -For every 'text' node it will scan for characters such as "<>&". -If it encounters such characters it will add the <![CDATA[ tag before and ]] tag after the 'text' node. -Else just write out the 'text' node. if (strspn($this->nodes[$root]["text"], "<>&") > 0) { // Add the character data to the XML data with CDATA tags around it. $xml .= $before." <![CDATA[\n"; $xml .= $before." ".$this->nodes[$root]["text"]."\n"; $xml .= $before." ]]>\n"; } else { // Add the character data to the XML data. $xml .= $before." ".$this->nodes[$root]["text"]."\n"; } Look for this comment in your xml.php under the get_file() function if you want to know where i put it. It's around line 355 // Add the character data to the XML data. -----Original Message----- From: rot...@ne... [mailto:rot...@ne...] Sent: Wednesday, July 04, 2001 12:13 AM To: us...@li... Subject: [phpXML] miss-match How can I get around phpXML's tendency to place tags inside regular text after the tag containing the text. i.e., <blah1> Text<blah2>more</blah2>text. </blah> Comes out Text text.more -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |
From: <ph...@pe...> - 2001-10-08 17:13:01
|
absolutely right, Nigel. The problem has nothing to do with CDATA - call it embedded structure, where the child(ren) is in the middle of the parent. Try the following: <text>There are 2 categories: <category>1</category> <category>2 which has <sub>a subcategory</sub> as well</category> which have to be taken into account.</text> etc etc. The parser adds an extra element to the array for each segment of a node, but phpxml's load_file ignores this and just adds the content to the node without any indication that there was a child in that position. Consequently, it loses information. (it also compounds the error by stripping the spaces around the tags, so "<text>The spacing is <e>very</e> important.</text>" comes out as "The spacingisimportant." :-) afaics, the only solution is to add an extra array to correspond to each segment, so my example above would be stored as text[0] e[0] text[1]. It gets pretty hairy though trying to put it back together again, as there is no limit to the number or levels of the array. I gave up trying to use php's parse_into_struct because my poor brain couldn't cope with navigating all the arrays! On Wednesday 04 July 2001 13:20, you wrote: > > I'm not sure that this actually solves the stated problem though as I think > I am right in saying that this is a fix that goes into get_file(). > Therefore if the datastructure can't describe "Before<tag>Middle</tag>End", > then it's not going to be able to print it. > > This fix will cope with usage of the object that make calls to > set_content("address","Some text <B>that</B> contains some markup."). But > if the xml file that you read in already has "Some text <B>that</B> > contains some markup." then the class is going to loose this structure in > the parse. > > Basically phpxml's internal datastructure is lossy. You can't read to > object and write back out to file and have two logically identical files. > Ideally it ought to be. > > We need a more complete fix for this in the constructor or load_from_file > function I think.... > > Nigel > > > How can I get around phpXML's tendency to place tags inside regular text > > after the tag containing the text. > > i.e., > > <blah1> > > Text<blah2>more</blah2>text. > > </blah> > > Comes out > > > > Text text.more > > -- > This message has been sent through the <phpXML/> user discussion list. To > unsubscribe, please visit > https://sslsites.de/mailinglisten/user/us...@li.../ -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |
From: <tom...@di...> - 2001-10-08 17:42:59
|
I was initially thrown off by the 'trivialness' of the example but when I look at how you intend to process the file it seems to cry out for a different structure altogether. Is it not true that _if_ there are children _then_ the children should stand as elements of the parent? ((then the other 'content' is/are really attributes of the parent)) That would say to me that the example being discussed could (should?) better be constructed like <blah1 precursor="Text" postcursor="text."> <blah2>more</blah2> </blah> Wouldn't that be more parallel to the processing that you intend to do to the file? my 2cents Tom At 08:10 PM 7/4/01 +0000, ph...@pe... wrote: >absolutely right, Nigel. The problem has nothing to do with CDATA - call it >embedded structure, where the child(ren) is in the middle of the parent. Try >the following: ><text>There are 2 categories: ><category>1</category> ><category>2 which has <sub>a subcategory</sub> as well</category> >which have to be taken into account.</text> >etc etc. >The parser adds an extra element to the array for each segment of a node, but >phpxml's load_file ignores this and just adds the content to the node without >any indication that there was a child in that position. Consequently, it >loses information. (it also compounds the error by stripping the spaces >around the tags, so "<text>The spacing is <e>very</e> important.</text>" >comes out as "The spacingisimportant." :-) > >afaics, the only solution is to add an extra array to correspond to each >segment, so my example above would be stored as text[0] e[0] text[1]. It gets >pretty hairy though trying to put it back together again, as there is no >limit to the number or levels of the array. I gave up trying to use php's >parse_into_struct because my poor brain couldn't cope with navigating all the >arrays! > > >On Wednesday 04 July 2001 13:20, you wrote: > > > > I'm not sure that this actually solves the stated problem though as I think > > I am right in saying that this is a fix that goes into get_file(). > > Therefore if the datastructure can't describe "Before<tag>Middle</tag>End", > > then it's not going to be able to print it. > > > > This fix will cope with usage of the object that make calls to > > set_content("address","Some text <B>that</B> contains some markup."). But > > if the xml file that you read in already has "Some text <B>that</B> > > contains some markup." then the class is going to loose this structure in > > the parse. > > > > Basically phpxml's internal datastructure is lossy. You can't read to > > object and write back out to file and have two logically identical files. > > Ideally it ought to be. > > > > We need a more complete fix for this in the constructor or load_from_file > > function I think.... > > > > Nigel > > > > > How can I get around phpXML's tendency to place tags inside regular text > > > after the tag containing the text. > > > i.e., > > > <blah1> > > > Text<blah2>more</blah2>text. > > > </blah> > > > Comes out > > > > > > Text text.more > > > > -- > > This message has been sent through the <phpXML/> user discussion list. To > > unsubscribe, please visit > > https://sslsites.de/mailinglisten/user/us...@li.../ > >-- >This message has been sent through the <phpXML/> user discussion list. To >unsubscribe, please visit >https://sslsites.de/mailinglisten/user/us...@li.../ -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |
From: <ph...@pe...> - 2001-10-08 16:31:03
|
On Wednesday 04 July 2001 22:01, you wrote: > I was initially thrown off by the 'trivialness' of the example but when I > look at how you intend to process the file it seems to cry out for a > different structure altogether. > > Is it not true that _if_ there are children _then_ the children should > stand as elements of the parent? ((then the other 'content' is/are really > attributes of the parent)) > > That would say to me that the example being discussed could (should?) > better be constructed like > > <blah1 precursor="Text" postcursor="text."> > <blah2>more</blah2> > </blah> > > Wouldn't that be more parallel to the processing that you intend to do to > the file? > > my 2cents > Tom the whole point of xml/xsl/etc is that it separates content from processing. One xml file can be processed in any number of different ways. If a processor, whether it be phpxml or anything else, can only handle files in a certain format, then it is of limited use. A general-purpose xml evaluator like phpxml _must_ be able to handle any valid xml file. If you want a non-trivial example, download any of the xml or xhtml TRs from W3C, then use Michael's nice little XPath Testing Environment script to evaluate it. You will soon see what the problem is. If you now tell the folk at W3C they should rewrite their documents so phpxml can handle them, I doubt whether you'll get a printable reply! -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |
From: <nig...@us...> - 2001-10-09 13:11:54
|
> I was initially thrown off by the 'trivialness' of the example but = when I=20 > look at how you intend to process the file it seems to cry out for a=20 > different structure altogether. >=20 > Is it not true that _if_ there are children _then_ the children should = > stand as elements of the parent? ((then the other 'content' is/are = really=20 > attributes of the parent)) >=20 > That would say to me that the example being discussed could (should?) = > better be constructed like >=20 > <blah1 precursor=3D"Text" postcursor=3D"text."> > <blah2>more</blah2> > </blah> >=20 > Wouldn't that be more parallel to the processing that you intend to do = to=20 > the file? The problem with this approach is when you come to an XML fragment like = this: <p>Hello there <b>my</b> name is <i>Nigel</i> Swinson</p> Where do we put the "name is" text with a precursor, postcursor = approach? Currently this is the structure that we obtain (This clearly shows the = "Hello therename isSwinson" text property of the /p[1] entry): We currently have I suggest we aim for =20 xml Object ( [nodes] =3D> Array ( [/p[1]] =3D> Array ( [context-position] =3D> 1 [document-position] =3D> 1 [name] =3D> p [text] =3D> Hello therename isSwinson [parent] =3D>=20 [attributes] =3D> Array ( ) [children] =3D> Array ( [b] =3D> 1 [i] =3D> 1 ) ) [] =3D> Array ( [document-position] =3D> 0 [children] =3D> Array ( [p] =3D> 1 ) ) [/p[1]/b[1]] =3D> Array ( [context-position] =3D> 1 [document-position] =3D> 2 [name] =3D> b [text] =3D> my [parent] =3D> /p[1] [attributes] =3D> Array ( ) ) [/p[1]/i[1]] =3D> Array ( [context-position] =3D> 1 [document-position] =3D> 2 [name] =3D> i [text] =3D> Nigel [parent] =3D> /p[1] [attributes] =3D> Array ( ) ) ) ) xml Object ( [nodes] =3D> Array ( [/p[1]] =3D> Array ( [context-position] =3D> 1 [document-position] =3D> 1 [name] =3D> p [text] =3D> "Hello there " [after-element-text] =3D> "" [parent] =3D>=20 [attributes] =3D> Array ( ) [children] =3D> Array ( [b] =3D> 1 [i] =3D> 1 ) ) [] =3D> Array ( [document-position] =3D> 0 [children] =3D> Array ( [p] =3D> 1 ) ) [/p[1]/b[1]] =3D> Array ( [context-position] =3D> 1 [document-position] =3D> 2 [name] =3D> b [text] =3D> "my" [after-element-text] =3D> " name is " [parent] =3D> /p[1] [attributes] =3D> Array ( ) ) [/p[1]/i[1]] =3D> Array ( [context-position] =3D> 1 [document-position] =3D> 2 [name] =3D> i [text] =3D> "Nigel" [after-element-text] =3D> " Swinson" [parent] =3D> /p[1] [attributes] =3D> Array ( ) ) ) )=20 =20 Using a system like this I think is scaleable, lossless, and wouldn't be = all that hard to implement. ? Nigel |
From: <nig...@us...> - 2001-10-09 13:11:14
|
> -When I call $xmlobj->get_file(); it will go through the = $xmlobj->nodes > array and format the XML document. > -For every 'text' node it will scan for characters such as "<>&". > -If it encounters such characters it will add the <![CDATA[ tag before > and ]] tag after the 'text' node. > -Else just write out the 'text' node. >=20 >=20 > if (strspn($this->nodes[$root]["text"], "<>&") > 0) { > // Add the character data to the XML data with CDATA tags around it. > $xml .=3D $before." <![CDATA[\n"; > $xml .=3D $before." ".$this->nodes[$root]["text"]."\n"; > $xml .=3D $before." ]]>\n"; > } else { > // Add the character data to the XML data. > $xml .=3D $before." ".$this->nodes[$root]["text"]."\n"; > } I'm not sure that this actually solves the stated problem though as I = think I am right in saying that this is a fix that goes into get_file(). = Therefore if the datastructure can't describe = "Before<tag>Middle</tag>End", then it's not going to be able to print = it. This fix will cope with usage of the object that make calls to = set_content("address","Some text <B>that</B> contains some markup."). = But if the xml file that you read in already has "Some text <B>that</B> = contains some markup." then the class is going to loose this structure = in the parse. Basically phpxml's internal datastructure is lossy. You can't read to = object and write back out to file and have two logically identical = files. Ideally it ought to be. We need a more complete fix for this in the constructor or = load_from_file function I think.... Nigel > How can I get around phpXML's tendency to place tags inside regular = text > after the tag containing the text. > i.e., > <blah1> > Text<blah2>more</blah2>text. > </blah> > Comes out >=20 > Text text.more -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |
From: <nig...@us...> - 2001-10-09 13:10:56
|
Try using a context of /government[1] The context (I think) has to be a COMPLETE address. Not just an XPath = address that evaluates to only one node. I haven't tested this, but I think this is right. Nigel ----- Original Message -----=20 From: <tom...@di...> To: <us...@li...> Sent: Wednesday, July 04, 2001 2:29 PM Subject: [phpXML] Need example for 'context' > Hello all, >=20 > I need a very specific example for the use of 'context' in the = original=20 > distro examples. >=20 > What are inputs that show a highlighted result ? > "XPath Expression:" > "XPath Context:" >=20 > E.g. what input for each field in the form testsuite.php (processing = the=20 > 'government.xml' file) >=20 > Whaterver combination I use (just one example) > Example (my entries) > XPath Expression: file://prename=20 > XPath Context: /government/person > - I get no result highlighted >=20 > Many thanks, > Tom >=20 >=20 > -- > This message has been sent through the <phpXML/> user discussion list. = To unsubscribe, please visit = https://sslsites.de/mailinglisten/user/us...@li.../ >=20 -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |