Re: processing-instructions not in node structure
Brought to you by:
bs_php,
nigelswinson
From: Nigel S. <nig...@us...> - 2002-07-06 11:35:23
|
> Hello all, > I've just joined the list and am beginning to study phpxpath. Welcome! It's good to have you aboard! > I am wondering why phpxpath doesn't include processing-instructions in > the node structure. Purely because we never got round to it, and as none of our applications have needed them, implementing them hasn't been a priority. This isn't to say that we aren't keen that they be supported eventually! > In my application, I need to include pi's in the document processing. > The following description is in phpxpath class doc: > > * | The main structure of a node is: > * | $node = array( > * | 'name' => '', # The tag name. E.g. In <FOO > bar="aaa"/> it would be 'FOO' > * | 'attributes' => array(), # The attributes of the tag E.g. In > <FOO bar="aaa"/> it would be array('bar'=>'aaa') > * | 'textParts' => array(), # Array of text parts surrounding the > children E.g. <FOO>aa<A>bb<B/>cc</A>dd</FOO> -> > array('aa','bb','cc','dd') > * | 'childNodes' => array(), # Array of refences (pointers) to > child nodes. > * | > > The above structure seems fine if you only have textParts and childNodes > - you can always know the order in which they occurred in the original > document. > > But if your original xml contained pi's, then it appears that phpxpath > doesn't keep track of the ordering relative to textParts and childNodes. Agreed. Supporting PIs means this would have to change. > Is there a workaround for this? Currently PIs are treated as text, so they are stuck in and processed with the surrounding text. So you get text nodes with embedded PIs. Here's the SAX handler, note the text append into the parsedTextLocation which will end up as the text entry in the text array of the node. /** * Handles processing instruction (PI) * * A processing instruction has the following format: * <? target data ? > e.g. <? dtd version="1.0" ? > * * Currently I have no bether idea as to left it 'as is' and treat the PI data as normal * text (and adding the surrounding PI-tags <? ? >). */ function _handlePI($parser, $target, $data) { $data = $this->_translateAmpersand($data, $reverse=TRUE); $this->parsedTextLocation .= "<?{$target} {$data}?>"; return TRUE; } > Does anyone else see a need? Yes. Ultimately we should do this properly. :o) Nigel |