00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 define( "EZ_XML_NODE_ELEMENT", 1 );
00053
00054
00055
00056 define( "EZ_XML_NODE_ATTRIBUTE", 2 );
00057
00058
00059
00060 define( "EZ_XML_NODE_TEXT", 3 );
00061
00062
00063
00064 define( "EZ_XML_NODE_CDATASECTION", 4 );
00065
00066 class eZDOMNode
00067 {
00068
00069
00070
00071 function eZDOMNode()
00072 {
00073 $this->content =& $this->value;
00074 $this->Content =& $this->content;
00075 $this->Name =& $this->tagname;
00076 $this->Type =& $this->type;
00077 $this->nodeName =& $this->Name;
00078 }
00079
00080
00081
00082
00083 function clone()
00084 {
00085 $tmp = new eZDOMNode();
00086 $tmp->Name = $this->Name;
00087 $tmp->Type = $this->Type;
00088 $tmp->Content = $this->Content;
00089 $tmp->Children = $this->Children;
00090 $tmp->Attributes = $this->Attributes;
00091 $tmp->NamespaceURI = $this->NamespaceURI;
00092 $tmp->LocalName = $this->LocalName;
00093 $tmp->Prefix = $this->Prefix;
00094 return $tmp;
00095 }
00096
00097
00098
00099
00100 function cleanup( &$node )
00101 {
00102 if ( $node->hasChildren() )
00103 {
00104 foreach( array_keys( $node->Children ) as $key )
00105 {
00106 $child =& $node->Children[$key];
00107 if ( $child->hasChildren() )
00108 {
00109 $child->cleanup( $child );
00110 }
00111
00112 }
00113 $node->removeChildren();
00114 }
00115 }
00116
00117
00118
00119
00120
00121
00122
00123 function name()
00124 {
00125 return $this->Name;
00126 }
00127
00128
00129
00130
00131 function setName( $name )
00132 {
00133 $this->Name = $name;
00134 $this->LocalName = $name;
00135 }
00136
00137
00138
00139
00140 function namespaceURI()
00141 {
00142 return $this->NamespaceURI;
00143 }
00144
00145
00146
00147
00148 function setNamespaceURI( $uri )
00149 {
00150 $this->NamespaceURI = $uri;
00151 }
00152
00153
00154
00155
00156 function localName()
00157 {
00158 return $this->LocalName;
00159 }
00160
00161
00162
00163
00164 function prefix()
00165 {
00166 return $this->Prefix;
00167 }
00168
00169
00170
00171
00172 function setPrefix( $value )
00173 {
00174 $this->Prefix = $value;
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 function type()
00187 {
00188 return $this->Type;
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 function setType( $type )
00201 {
00202 $this->Type = $type;
00203 }
00204
00205
00206
00207
00208
00209
00210 function &content()
00211 {
00212 return $this->Content;
00213 }
00214
00215
00216
00217
00218
00219
00220 function setContent( $content )
00221 {
00222 $this->Content = $content;
00223 }
00224
00225
00226
00227
00228
00229
00230 function &attributes()
00231 {
00232 return $this->Attributes;
00233 }
00234
00235
00236
00237
00238
00239
00240 function &attributesNS( $namespaceURI )
00241 {
00242 $ret = array();
00243 if ( count( $this->Attributes ) > 0 )
00244 {
00245 foreach ( $this->Attributes as $attribute )
00246 {
00247 if ( $attribute->namespaceURI() == $namespaceURI )
00248 {
00249
00250 $ret[] = $attribute;
00251 }
00252 }
00253 }
00254 return $ret;
00255 }
00256
00257
00258
00259
00260
00261
00262 function hasAttributes()
00263 {
00264 return count( $this->Attributes ) > 0;
00265 }
00266
00267
00268
00269
00270
00271
00272 function attributeCount()
00273 {
00274 return count( $this->Attributes );
00275 }
00276
00277
00278
00279
00280
00281
00282 function &children()
00283 {
00284 return $this->Children;
00285 }
00286
00287
00288
00289
00290
00291
00292 function hasChildren()
00293 {
00294 return count( $this->Children ) > 0;
00295 }
00296
00297
00298
00299
00300
00301
00302 function childrenCount()
00303 {
00304 return count( $this->Children );
00305 }
00306
00307
00308
00309
00310
00311
00312 function first_child()
00313 {
00314 return isset( $this->Children[0] ) ? $this->Children[0] : null;
00315 }
00316
00317
00318
00319
00320
00321
00322 function node_value()
00323 {
00324 return $this->Content;
00325 }
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 function &elementChildrenByName( $name )
00336 {
00337 $element =& $this->elementByName( $name );
00338 if ( !$element )
00339 {
00340 $children = false;
00341 return $children;
00342 }
00343 return $element->children();
00344 }
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 function &elementFirstChildByName( $name )
00355 {
00356 $element =& $this->elementByName( $name );
00357 if ( !$element )
00358 {
00359 $child = false;
00360 return $child;
00361 }
00362 return $element->firstChild();
00363 }
00364
00365
00366
00367
00368
00369
00370
00371
00372 function &elementByName( $name )
00373 {
00374 $element = false;
00375 foreach ( array_keys( $this->Children ) as $key )
00376 {
00377 $child =& $this->Children[$key];
00378 if ( $child->name() == $name )
00379 {
00380 if ( $element )
00381 {
00382 $retValue = false;
00383 return $retValue;
00384 }
00385 $element =& $child;
00386 }
00387 }
00388 return $element;
00389 }
00390
00391
00392
00393
00394 function get_elements_by_tagname( $name )
00395 {
00396 $elements = array();
00397 foreach ( array_keys( $this->Children ) as $key )
00398 {
00399 $child =& $this->Children[$key];
00400 if ( $child->name() == $name )
00401 $elements[] =& $child;
00402 }
00403
00404 return $elements;
00405 }
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415 function elementTextContentByName( $name )
00416 {
00417 $element = $this->elementByName( $name );
00418 if ( !$element )
00419 {
00420 return false;
00421 }
00422
00423 return $element->textContent();
00424 }
00425
00426
00427
00428
00429
00430
00431
00432 function &elementByAttributeValue( $attr, $value )
00433 {
00434 foreach ( array_keys( $this->Children ) as $key )
00435 {
00436 $child =& $this->Children[$key];
00437 if ( $child->attributeValue( $attr ) == $value )
00438 {
00439 return $child;
00440 }
00441 }
00442
00443 unset( $child );
00444 $child = false;
00445 return $child;
00446 }
00447
00448
00449
00450
00451
00452
00453
00454 function &elementsByName( $name )
00455 {
00456 $elements = array();
00457 foreach ( array_keys( $this->Children ) as $key )
00458 {
00459 $child =& $this->Children[$key];
00460 if ( $child->name() == $name )
00461 {
00462 $elements[] =& $child;
00463 }
00464 }
00465 return $elements;
00466 }
00467
00468
00469
00470
00471
00472
00473
00474 function &elementsTextContentByName( $name )
00475 {
00476 $elements = array();
00477 foreach ( array_keys( $this->Children ) as $key )
00478 {
00479 $child =& $this->Children[$key];
00480 if ( $child->name() == $name )
00481 {
00482 $elements[] = $child->textContent();
00483 }
00484 }
00485 return $elements;
00486 }
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497 function attributeValue( $attributeName )
00498 {
00499 $returnValue = false;
00500 foreach ( $this->Attributes as $attribute )
00501 {
00502 if ( $attribute->name() == $attributeName )
00503 $returnValue = $attribute->content();
00504 }
00505
00506 return $returnValue;
00507 }
00508
00509
00510
00511
00512 function get_attribute( $attributeName )
00513 {
00514 return $this->attributeValue( $attributeName );
00515 }
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525 function elementAttributeValueByName( $name, $attributeName )
00526 {
00527 $element = $this->elementByName( $name );
00528 if ( !$element )
00529 return false;
00530 else
00531 return $element->attributeValue( $attributeName );
00532 }
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569 function attributeValues( $attributeDefinitions = false, $defaultValue = null )
00570 {
00571 $hash = array();
00572 foreach ( $this->Attributes as $attribute )
00573 {
00574 if ( $attributeDefinitions === false )
00575 {
00576 $hash[$attribute->name()] = $attribute->content();
00577 continue;
00578 }
00579
00580 foreach ( $attributeDefinitions as $attributeName => $keyName )
00581 {
00582 if ( $attribute->name() == $attributeName )
00583 {
00584 $hash[$keyName] = $attribute->content();
00585 break;
00586 }
00587 }
00588 }
00589 if ( $defaultValue !== null )
00590 {
00591 foreach ( $attributeDefinitions as $attributeName => $keyName )
00592 {
00593 if ( !isset( $hash[$keyName] ) )
00594 $hash[$keyName] = $defaultValue;
00595 }
00596 }
00597
00598 return $hash;
00599 }
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610 function attributeValueNS( $attributeName, $namespaceURI )
00611 {
00612 $returnValue = false;
00613 if ( count( $this->Attributes ) > 0 )
00614 {
00615 foreach ( $this->Attributes as $attribute )
00616 {
00617 if ( $attribute->name() == $attributeName &&
00618 $attribute->namespaceURI() == $namespaceURI )
00619 {
00620
00621 $returnValue = $attribute->content();
00622 }
00623 }
00624 }
00625
00626 return $returnValue;
00627 }
00628
00629
00630
00631
00632
00633
00634
00635
00636 function appendChild( &$node )
00637 {
00638 if ( get_class( $node ) == "ezdomnode" )
00639 {
00640 if ( $this->parentNode !== false )
00641 $node->parentNode =& $this;
00642
00643 $this->Children[] =& $node;
00644 return $node;
00645 }
00646 return false;
00647 }
00648
00649
00650
00651
00652 function append_child( &$node )
00653 {
00654 return $this->appendChild( $node );
00655 }
00656
00657
00658
00659
00660
00661
00662
00663
00664 function appendAttribute( &$node )
00665 {
00666 if ( get_class( $node ) == "ezdomnode" )
00667 {
00668 $this->Attributes[] =& $node;
00669 return $node;
00670 }
00671 return false;
00672 }
00673
00674 function set_attribute( $name, $value )
00675 {
00676 $this->removeNamedAttribute( $name );
00677 return $this->appendAttribute( eZDOMDocument::createAttributeNode( $name, $value ) );
00678 }
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708 function appendAttributes( $attributeValues,
00709 $attributeDefinitions,
00710 $includeEmptyValues = false )
00711 {
00712 foreach ( $attributeDefinitions as $attributeXMLName => $attributeKey )
00713 {
00714 if ( $includeEmptyValues or
00715 ( isset( $attributeValues[$attributeKey] ) and
00716 $attributeValues[$attributeKey] !== false ) )
00717 {
00718 $value = false;
00719 if ( isset( $attributeValues[$attributeKey] ) and
00720 $attributeValues[$attributeKey] !== false )
00721 $value = $attributeValues[$attributeKey];
00722 $this->Attributes[] = eZDOMDocument::createAttributeNode( $attributeXMLName, $value );
00723 }
00724 }
00725 }
00726
00727
00728
00729
00730
00731
00732
00733 function removeNamedAttribute( $name )
00734 {
00735 $removed = false;
00736 foreach( array_keys( $this->Attributes ) as $key )
00737 {
00738 if ( $this->Attributes[$key]->name() == $name )
00739 {
00740 unset( $this->Attributes[$key] );
00741 $removed = true;
00742 }
00743 }
00744 return $removed;
00745 }
00746
00747
00748
00749
00750 function remove_attribute( $name )
00751 {
00752 return $this->removeNamedAttribute( $name );
00753 }
00754
00755
00756
00757
00758
00759
00760 function removeAttributes()
00761 {
00762 $this->Attributes = array();
00763 }
00764
00765
00766
00767
00768
00769
00770
00771 function removeNamedChildren( $name )
00772 {
00773 $removed = false;
00774 foreach( array_keys( $this->Children ) as $key )
00775 {
00776 if ( $this->Children[$key]->name() == $name )
00777 {
00778 if ( $this->parentNode !== false )
00779 {
00780 unset( $this->Children[$key]->parentNode );
00781 $this->Children[$key]->parentNode = null;
00782 }
00783 unset( $this->Children[$key] );
00784 $removed = true;
00785 }
00786 }
00787 return $removed;
00788 }
00789
00790
00791
00792
00793
00794
00795 function removeChildren()
00796 {
00797 if ( $this->parentNode !== false )
00798 {
00799 foreach( array_keys( $this->Children ) as $key )
00800 {
00801 unset( $this->Children[$key]->parentNode );
00802 $this->Children[$key]->parentNode = null;
00803 }
00804 }
00805
00806 $this->Children = array();
00807 }
00808
00809
00810
00811
00812
00813
00814 function removeLastChild()
00815 {
00816 end( $this->Children );
00817 $key = key( $this->Children );
00818 if ( $this->parentNode !== false )
00819 {
00820 unset( $this->Children[$key]->parentNode );
00821 $this->Children[$key]->parentNode = null;
00822 }
00823
00824 unset( $this->Children[$key] );
00825 }
00826
00827
00828
00829
00830
00831
00832 function removeChild( &$childToRemove )
00833 {
00834 if ( $childToRemove->parentNode !== false )
00835 {
00836 unset( $childToRemove->parentNode );
00837 $childToRemove->parentNode = null;
00838 }
00839 $childToRemove->flag = true;
00840
00841 foreach ( array_keys( $this->Children ) as $key )
00842 {
00843 if ( $this->Children[$key]->flag === true )
00844 {
00845 unset( $this->Children[$key] );
00846 break;
00847 }
00848 }
00849 $childToRemove->flag = false;
00850 }
00851
00852
00853
00854
00855
00856
00857
00858 function textContent()
00859 {
00860 return $this->collectTextContent( $this );
00861 }
00862
00863 function collectTextContent( &$element )
00864 {
00865 $ret = '';
00866 if ( $element->Type == EZ_XML_NODE_TEXT or
00867 $element->Type == EZ_XML_NODE_CDATASECTION )
00868 {
00869 $ret = $element->content();
00870 }
00871 else
00872 {
00873 if ( count( $element->Children ) > 0 )
00874 {
00875 foreach( array_keys( $element->Children ) as $key )
00876 {
00877 $child =& $element->Children[$key];
00878 $ret .= $this->collectTextContent( $child );
00879 }
00880 }
00881 }
00882 return $ret;
00883 }
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904 function toString( $level, $charset = false, $convertSpecialChars = true )
00905 {
00906 $spacer = str_repeat( " ", $level*2 );
00907 $ret = "";
00908 switch ( $this->Name )
00909 {
00910 case "#text" :
00911 {
00912 $tagContent = $this->Content;
00913
00914 if ( $convertSpecialChars )
00915 {
00916 $tagContent = str_replace( "&", "&", $tagContent );
00917 $tagContent = str_replace( ">", ">", $tagContent );
00918 $tagContent = str_replace( "<", "<", $tagContent );
00919 $tagContent = str_replace( "'", "'", $tagContent );
00920 $tagContent = str_replace( '"', """, $tagContent );
00921 }
00922
00923 $ret = $tagContent;
00924 }break;
00925
00926 case "#cdata-section" :
00927 {
00928 $ret = "<![CDATA[";
00929 $ret .= $this->Content;
00930 $ret .= "]]>";
00931 }break;
00932
00933 default :
00934 {
00935 $isOneLiner = false;
00936
00937 if ( count( $this->Children ) == 0 and ( $this->Content == "" ) )
00938 $isOneLiner = true;
00939
00940 $attrStr = "";
00941
00942
00943 if ( $this->namespaceURI() != "" )
00944 {
00945 $attrPrefix = "";
00946 if ( $this->Prefix != "" )
00947 $attrPrefix = ":" . $this->prefix();
00948 $attrStr = " xmlns" . $attrPrefix . "=\"" . $this->namespaceURI() . "\"";
00949 }
00950
00951 $prefix = "";
00952 if ( $this->Prefix != false )
00953 $prefix = $this->Prefix. ":";
00954
00955
00956 if ( count( $this->Attributes ) > 0 )
00957 {
00958 $i = 0;
00959 foreach ( $this->Attributes as $attr )
00960 {
00961 $attrPrefix = "";
00962 if ( $attr->prefix() != false )
00963 $attrPrefix = $attr->prefix(). ":";
00964
00965 if ( $i > 0 )
00966 $attrStr .= "\n" . $spacer . str_repeat( " ", strlen( $prefix . $this->Name ) + 1 + 1 );
00967 else
00968 $attrStr .= ' ';
00969
00970 $attrContent = $attr->content();
00971 $attrContent = str_replace( "&", "&", $attrContent );
00972 $attrContent = str_replace( ">", ">", $attrContent );
00973 $attrContent = str_replace( "<", "<", $attrContent );
00974 $attrContent = str_replace( "'", "'", $attrContent );
00975 $attrContent = str_replace( '"', """, $attrContent );
00976
00977 $attrStr .= $attrPrefix . $attr->name() . "=\"" . $attrContent . "\"";
00978 ++$i;
00979 }
00980 }
00981
00982 if ( $isOneLiner )
00983 $oneLinerEnd = " /";
00984 else
00985 $oneLinerEnd = "";
00986
00987 $ret = '';
00988
00989 if ( $this->Name =='link' )
00990 {
00991 $ret .= "<" . $prefix . $this->Name . $attrStr . $oneLinerEnd . ">";
00992 }
00993 else
00994 {
00995 if ( $level > 0 )
00996 $ret .= "\n";
00997 $ret .= "$spacer<" . $prefix . $this->Name . $attrStr . $oneLinerEnd . ">";
00998 }
00999
01000 $lastChildType = false;
01001 if ( count( $this->Children ) > 0 )
01002 {
01003 foreach ( $this->Children as $child )
01004 {
01005 $ret .= $child->toString( $level + 1, $charset, $convertSpecialChars );
01006 $lastChildType = $child->type();
01007 }
01008 }
01009
01010 if ( !$isOneLiner )
01011 {
01012 if ( $lastChildType == 1 )
01013 $ret .= "\n$spacer";
01014 $ret .= "</" . $prefix . $this->Name . ">";
01015 }
01016
01017
01018 }break;
01019 }
01020 return $ret;
01021 }
01022
01023
01024
01025
01026 function dump_mem( $format, $charset = false )
01027 {
01028 return $this->toString( 0, $charset);
01029 }
01030
01031
01032
01033
01034
01035
01036
01037 function setAttribute( $name, $value )
01038 {
01039 foreach ( $this->Attributes as $attribute )
01040 {
01041 if ( $attribute->name() == $name )
01042 {
01043 $attribute->setContent( $value );
01044 return $attribute;
01045 }
01046 }
01047
01048 $attr = eZDOMDocument::createAttribute( $name );
01049 $attr->setContent( $value );
01050 return $this->appendAttribute( $attr );
01051 }
01052
01053
01054
01055 function setAttributeNS( $namespaceURI, $qualifiedName, $value )
01056 {
01057 foreach ( $this->Attributes as $attribute )
01058 {
01059 if ( !$attribute->Prefix )
01060 continue;
01061
01062 $fullName = $attribute->Prefix . ':' . $attribute->LocalName;
01063 if ( $fullName == $qualifiedName )
01064 {
01065 $attribute->setContent( $value );
01066 return $attribute;
01067 }
01068 }
01069 $attr = eZDOMDocument::createAttributeNS( $namespaceURI, $qualifiedName );
01070 $attr->setContent( $value );
01071 return $this->appendAttribute( $attr );
01072 }
01073
01074
01075 function getAttribute( $attributeName )
01076 {
01077 $returnValue = '';
01078 foreach ( $this->Attributes as $attribute )
01079 {
01080 if ( $attribute->name() == $attributeName && !$attribute->Prefix )
01081 $returnValue = $attribute->Content;
01082 }
01083
01084 return $returnValue;
01085 }
01086
01087
01088 function getAttributeNS( $namespaceURI, $localName )
01089 {
01090 $returnValue = '';
01091 foreach ( $this->Attributes as $attribute )
01092 {
01093 if ( $attribute->LocalName == $localName &&
01094 $attribute->NamespaceURI == $namespaceURI )
01095 $returnValue = $attribute->Content;
01096 }
01097
01098 return $returnValue;
01099 }
01100
01101
01102 function removeAttribute( $name )
01103 {
01104 $removed = false;
01105 foreach( array_keys( $this->Attributes ) as $key )
01106 {
01107 if ( $this->Attributes[$key]->name() == $name && !$this->Attributes[$key]->Prefix )
01108 {
01109 unset( $this->Attributes[$key] );
01110 $removed = true;
01111 }
01112 }
01113 return $removed;
01114 }
01115
01116
01117 function removeAttributeNS( $namespaceURI, $localName )
01118 {
01119 $removed = false;
01120 foreach( array_keys( $this->Attributes ) as $key )
01121 {
01122 if ( $this->Attributes[$key]->LocalName == $localName &&
01123 $this->Attributes[$key]->NamespaceURI == $namespaceURI )
01124 {
01125 unset( $this->Attributes[$key] );
01126 $removed = true;
01127 }
01128 }
01129 return $removed;
01130 }
01131
01132
01133
01134
01135 function hasChildNodes()
01136 {
01137 return count( $this->Children ) > 0;
01138 }
01139
01140
01141
01142
01143
01144
01145
01146
01147 function &firstChild()
01148 {
01149 if ( count( $this->Children ) == 0 )
01150 {
01151 $child = false;
01152 return $child;
01153 }
01154 reset( $this->Children );
01155 $key = key( $this->Children );
01156 $child =& $this->Children[$key];
01157
01158 return $child;
01159 }
01160
01161
01162
01163
01164
01165
01166
01167 function &lastChild()
01168 {
01169 if ( count( $this->Children ) == 0 )
01170 {
01171 $child = false;
01172 return $child;
01173 }
01174 end( $this->Children );
01175 $key = key( $this->Children );
01176 $child =& $this->Children[$key];
01177
01178 return $child;
01179 }
01180
01181
01182
01183
01184
01185
01186 function replaceChild( &$newChild, &$oldChild )
01187 {
01188 if ( $this->parentNode !== false )
01189 {
01190 unset( $oldChild->parentNode );
01191 $oldChild->parentNode = null;
01192 }
01193 $oldChild->flag = true;
01194
01195 $newChildren = array();
01196
01197 foreach( array_keys( $this->Children ) as $key )
01198 {
01199 if ( $this->Children[$key]->flag === true )
01200 {
01201 if ( $this->parentNode !== false )
01202 $newChild->parentNode =& $this;
01203
01204 $newChildren[$key] =& $newChild;
01205 }
01206 else
01207 {
01208 $newChildren[$key] =& $this->Children[$key];
01209 }
01210 }
01211 $this->Children =& $newChildren;
01212 $oldChild->flag = false;
01213
01214 return $oldChild;
01215 }
01216
01217
01218
01219
01220
01221
01222 function insertBefore( &$newNode, &$refNode )
01223 {
01224 $refNode->flag = true;
01225
01226 $newChildren = array();
01227
01228 foreach ( array_keys( $this->Children ) as $key )
01229 {
01230 if ( $this->Children[$key]->flag === true )
01231 {
01232 $newChildren[] =& $newNode;
01233 if ( $this->parentNode !== false )
01234 {
01235 $newNode->parentNode =& $this;
01236 }
01237 }
01238 $newChildren[] =& $this->Children[$key];
01239 }
01240 $this->Children =& $newChildren;
01241 $refNode->flag = false;
01242 return $newNode;
01243 }
01244
01245
01246
01247
01248
01249 function &nextSibling()
01250 {
01251 $ret = null;
01252 if ( !$this->parentNode )
01253 return $ret;
01254
01255 $parent =& $this->parentNode;
01256 $this->flag = true;
01257
01258 $next = false;
01259 $children =& $parent->Children;
01260
01261 foreach( array_keys( $children ) as $child_key )
01262 {
01263 if ( $next )
01264 {
01265 $ret =& $children[$child_key];
01266 break;
01267 }
01268 elseif ( $children[$child_key]->flag === true )
01269 {
01270 $next = true;
01271 }
01272 }
01273 $this->flag = false;
01274
01275 return $ret;
01276 }
01277
01278
01279
01280
01281
01282 function &previousSibling()
01283 {
01284 $ret = null;
01285 if ( !$this->parentNode )
01286 return $ret;
01287
01288 $parent =& $this->parentNode;
01289 $this->flag = true;
01290
01291 $prev = false;
01292 $children =& $parent->Children;
01293 foreach( array_keys( $children ) as $child_key )
01294 {
01295 if ( $prev !== false && $children[$child_key]->flag === true )
01296 {
01297 $ret =& $children[$prev];
01298 break;
01299 }
01300 $prev = $child_key;
01301 }
01302 $this->flag = false;
01303 return $ret;
01304 }
01305
01306
01307
01308
01309
01310
01311
01312 function writeDebug( &$node, $text, $showAttributes = false, $showParent = false )
01313 {
01314 if ( !$node )
01315 $node =& $this;
01316
01317 if ( $node )
01318 {
01319 if ( get_class( $node ) == 'ezdomnode' )
01320 {
01321 $d = eZDOMNode::debugNode( $node, $showAttributes, $showParent );
01322 eZDebug::writeDebug( $d, $text );
01323 }
01324 else
01325 eZDebug::writeDebug( $node, $text );
01326 }
01327 else
01328 {
01329 eZDebug::writeDebug( array( $node ), $text );
01330 }
01331 }
01332
01333 function debugNode( &$node, $showAttributes, $showParent )
01334 {
01335 $d = array();
01336 $d['name'] = $node->nodeName;
01337 if ( $node->nodeName == '#text' )
01338 $d['text'] = $node->content;
01339 else if ( $node->Type == 2 )
01340 $d['value'] = $node->value;
01341
01342 if ( $showParent )
01343 $d['parent'] = $node->parentNode->nodeName;
01344
01345 if ( count( $node->Children ) )
01346 {
01347 $d['children'] = array();
01348 foreach( array_keys($node->Children) as $child_key )
01349 {
01350 $d['children'][] = eZDOMNode::debugNode( $node->Children[$child_key], $showAttributes, $showParent );
01351 }
01352 }
01353
01354 if ( $showAttributes && count( $node->Attributes ) )
01355 {
01356 $d['attributes'] = array();
01357 foreach( array_keys($node->Attributes) as $attr_key )
01358 {
01359 $d['attributes'][] = eZDOMNode::debugNode( $node->Attributes[$attr_key], $showAttributes, $showParent );
01360 }
01361 }
01362 return $d;
01363 }
01364
01365
01366
01367
01368
01369
01370 function writeDebugStr( &$node, $text )
01371 {
01372 if ( is_object( $node ) )
01373 eZDebug::writeDebug( $node->toString( 0 ), $text );
01374 else
01375 eZDebug::writeDebug( $node, $text );
01376 }
01377
01378
01379
01380
01381 var $Name = false;
01382
01383
01384 var $tagname = null;
01385
01386
01387 var $nodeName = null;
01388
01389
01390 var $type;
01391 var $Type = EZ_XML_NODE_ELEMENT;
01392
01393
01394 var $content = "";
01395 var $Content = "";
01396 var $value = '';
01397
01398
01399 var $Children = array();
01400
01401
01402 var $Attributes = array();
01403
01404
01405 var $NamespaceURI = false;
01406
01407
01408 var $LocalName = false;
01409
01410
01411 var $Prefix = false;
01412
01413
01414
01415
01416 var $parentNode = false;
01417
01418
01419 var $flag = false;
01420 }
01421
01422 ?>