Zacznijmy kurs

DOM XML Functions

XXXI. DOM XML Functions

Wstęp

The DOM XML extension has been overhauled in PHP 4.3.0 to better comply with the DOM standard. The extension still contains many old functions, but they should no longer be used. In particular, functions that are not object-oriented should be avoided.

The extension allows you to operate on an XML document with the DOM API. It also provides a function domxml_xmltree() to turn the complete XML document into a tree of PHP objects. Currently, this tree should be considered read-only - you can modify it, but this would not make any sense since DomDocument_dump_mem() cannot be applied to it. Therefore, if you want to read an XML file and write a modified version, use DomDocument_create_element(), DomDocument_create_text_node(), set_attribute(), etc. and finally the DomDocument_dump_mem() function.

Notatka: To rozszerzenie zostało przeniesione do repozytorium PECL i nie jest rozprowadzane z PHP od wersji 5.0.0.

Notatka: This extension is no longer marked experimental. It will, however, never be released with PHP 5, and will only be distributed with PHP 4. If you need DOM XML support with PHP 5 you can use the DOM extension. This domxml extension is not compatible with the DOM extension.

Wymagania

This extension makes use of the GNOME XML library. Download and install this library. You will need at least libxml-2.4.14. To use DOM XSLT features you can use the libxslt library and EXSLT enhancements from http://www.exslt.org/. Download and install these libraries if you plan to use (enhanced) XSLT features. You will need at least libxslt-1.0.18.

Instalacja

To rozszerzenie PECL nie jest dołączane do PHP. Informacje na temat instalacji tego rozszerzenia PECL można znaleźć w podręczniku w rozdziale zatytułowanym Instalacja rozszerzeń PECL. Dodatkowe informacje, takie jak nowe wersje, pliki do pobrania, pliki źródłowe, informacje o opiekunach czy rejestr zmian, można znaleźć tutaj: http://pecl.php.net/package/domxml.

W PHP 4 to rozszerzenie PECL można znaleźć w podkatalogu ext/ źródeł PHP lub pod znajdującym się wyżej odnośnikiem PECL. This extension is only available if PHP was configured with --with-dom[=DIR]. Add --with-dom-xslt[=DIR] to include DOM XSLT support. DIR is the libxslt install directory. Add --with-dom-exslt[=DIR] to include DOM EXSLT support, where DIR is the libexslt install directory.

Windows users will enable php_domxml.dll inside of php.ini in order to use these functions. W PHP 4 ten DLL znajduje się w podkatalogu extensions/ binarnej dystrybucji PHP dla Windows. DLL z tym rozszerzeniem PECL można pobrać ze strony PHP Downloads lub http://snaps.php.net/. Also, there is one additional DLL that must be made available to your system's PATH in order for this extension to work. In PHP 4 this is in the dlls/ directory. It's name: For PHP <= 4.2.0, it's libxml2.dll. For PHP >= 4.3.0, it's iconv.dll. And as of PHP 5.0.0, iconv is compiled into your Windows PHP binaries by default so no extra DLL is needed.

Deprecated functions

There are quite a few functions that do not fit into the DOM standard and should no longer be used. These functions are listed in the following table. The function DomNode_append_child() has changed its behaviour. It now adds a child and not a sibling. If this breaks your application, use the non-DOM function DomNode_append_sibling().

Tabela 1. Deprecated functions and their replacements

Old functionNew function
xmldocdomxml_open_mem()
xmldocfiledomxml_open_file()
domxml_new_xmldocdomxml_new_doc()
domxml_dump_memDomDocument_dump_mem()
domxml_dump_mem_fileDomDocument_dump_file()
DomDocument_dump_mem_fileDomDocument_dump_file()
DomDocument_add_rootDomDocument_create_element() followed by DomNode_append_child()
DomDocument_dtdDomDocument_doctype()
DomDocument_rootDomDocument_document_element()
DomDocument_childrenDomNode_child_nodes()
DomDocument_imported_nodeNo replacement.
DomNode_add_childCreate a new node with e.g. DomDocument_create_element() and add it with DomNode_append_child().
DomNode_childrenDomNode_child_nodes()
DomNode_parentDomNode_parent_node()
DomNode_new_childCreate a new node with e.g. DomDocument_create_element() and add it with DomNode_append_child().
DomNode_set_contentCreate a new node with e.g. DomDocument_create_text_node() and add it with DomNode_append_child().
DomNode_get_contentContent is just a text node and can be accessed with DomNode_child_nodes().
DomNode_set_contentContent is just a text node and can be added with DomNode_append_child().

Stałe predefiniowane

Poniższe stałe są zdefiniowane w tym rozszerzeniu i stają się dostępne, gdy rozszerzenie jest dokompilowane do PHP, lub załadowane dynamicznie przy starcie.

Tabela 2. XML constants

ConstantValueDescription
XML_ELEMENT_NODE (integer) 1Node is an element
XML_ATTRIBUTE_NODE (integer) 2Node is an attribute
XML_TEXT_NODE (integer) 3Node is a piece of text
XML_CDATA_SECTION_NODE (integer) 4 
XML_ENTITY_REF_NODE (integer) 5 
XML_ENTITY_NODE (integer) 6Node is an entity like &nbsp;
XML_PI_NODE (integer) 7Node is a processing instruction
XML_COMMENT_NODE (integer) 8Node is a comment
XML_DOCUMENT_NODE (integer) 9Node is a document
XML_DOCUMENT_TYPE_NODE (integer) 10 
XML_DOCUMENT_FRAG_NODE (integer) 11 
XML_NOTATION_NODE (integer) 12 
XML_GLOBAL_NAMESPACE (integer) 1 
XML_LOCAL_NAMESPACE (integer) 2 
XML_HTML_DOCUMENT_NODE (integer)   
XML_DTD_NODE (integer)   
XML_ELEMENT_DECL_NODE (integer)   
XML_ATTRIBUTE_DECL_NODE (integer)   
XML_ENTITY_DECL_NODE (integer)   
XML_NAMESPACE_DECL_NODE (integer)   
XML_ATTRIBUTE_CDATA (integer)   
XML_ATTRIBUTE_ID (integer)   
XML_ATTRIBUTE_IDREF (integer)   
XML_ATTRIBUTE_IDREFS (integer)   
XML_ATTRIBUTE_ENTITY (integer)   
XML_ATTRIBUTE_NMTOKEN (integer)   
XML_ATTRIBUTE_NMTOKENS (integer)   
XML_ATTRIBUTE_ENUMERATION (integer)   
XML_ATTRIBUTE_NOTATION (integer)   
XPATH_UNDEFINED (integer)   
XPATH_NODESET (integer)   
XPATH_BOOLEAN (integer)   
XPATH_NUMBER (integer)   
XPATH_STRING (integer)   
XPATH_POINT (integer)   
XPATH_RANGE (integer)   
XPATH_LOCATIONSET (integer)   
XPATH_USERS (integer)   
XPATH_NUMBER (integer)   

Classes

The API of the module follows the DOM Level 2 standard as closely as possible. Consequently, the API is fully object-oriented. It is a good idea to have the DOM standard available when using this module. Though the API is object-oriented, there are many functions which can be called in a non-object-oriented way by passing the object to operate on as the first argument. These functions are mainly to retain compatibility to older versions of the extension, and should not be used when creating new scripts.

This API differs from the official DOM API in two ways. First, all class attributes are implemented as functions with the same name. Secondly, the function names follow the PHP naming convention. This means that a DOM function lastChild() will be written as last_child().

This module defines a number of classes, which are listed - including their method - in the following tables. Classes with an equivalent in the DOM standard are named DOMxxx.

Tabela 3. List of classes

Class nameParent classes
DomAttributeDomNode
DomCDataDomNode
DomCommentDomCData : DomNode
DomDocumentDomNode
DomDocumentTypeDomNode
DomElementDomNode
DomEntityDomNode
DomEntityReferenceDomNode
DomProcessingInstructionDomNode
DomTextDomCData : DomNode
ParserCurrently still called DomParser
XPathContext 

Tabela 4. DomDocument class (DomDocument : DomNode)

Method nameFunction nameRemark
doctypeDomDocument_doctype() 
document_elementDomDocument_document_element() 
create_elementDomDocument_create_element() 
create_text_nodeDomDocument_create_text_node() 
create_commentDomDocument_create_comment() 
create_cdata_sectionDomDocument_create_cdata_section() 
create_processing_instructionDomDocument_create_processing_instruction() 
create_attributeDomDocument_create_attribute() 
create_entity_referenceDomDocument_create_entity_reference() 
get_elements_by_tagnameDomDocument_get_elements_by_tagname() 
get_element_by_idDomDocument_get_element_by_id() 
dump_memDomDocument_dump_mem()not DOM standard
dump_fileDomDocument_dump_file()not DOM standard
html_dump_memDomDocument_html_dump_mem()not DOM standard
xpath_initxpath_initnot DOM standard
xpath_new_contextxpath_new_contextnot DOM standard
xptr_new_contextxptr_new_contextnot DOM standard

Tabela 5. DomElement class (DomElement : DomNode)

Method nameFunction nameRemark
tagnameDomElement_tagname() 
get_attributeDomElement_get_attribute() 
set_attributeDomElement_set_attribute() 
remove_attributeDomElement_remove_attribute() 
get_attribute_nodeDomElement_get_attribute_node() 
set_attribute_nodeDomElement_set_attribute_node() 
get_elements_by_tagnameDomElement_get_elements_by_tagname() 
has_attributeDomElement_has_attribute() 

Tabela 7. DomAttribute class (DomAttribute : DomNode)

Method name Remark
nameDomAttribute_name() 
valueDomAttribute_value() 
specifiedDomAttribute_specified() 

Tabela 8. DomProcessingInstruction class (DomProcessingInstruction : DomNode)

Method nameFunction nameRemark
targetDomProcessingInstruction_target() 
dataDomProcessingInstruction_data() 

Tabela 9. Parser class

Method nameFunction nameRemark
add_chunkParser_add_chunk() 
endParser_end() 

Tabela 10. XPathContext class

Method nameFunction nameRemark
evalXPathContext_eval() 
eval_expressionXPathContext_eval_expression() 
register_nsXPathContext_register_ns() 

Tabela 11. DomDocumentType class (DomDocumentType : DomNode)

Method nameFunction nameRemark
nameDomDocumentType_name() 
entitiesDomDocumentType_entities() 
notationsDomDocumentType_notations() 
public_idDomDocumentType_public_id() 
system_idDomDocumentType_system_id() 
internal_subsetDomDocumentType_internal_subset() 

The classes DomDtd is derived from DomNode. DomComment is derived from DomCData.

Przykłady

Many examples in this reference require an XML string. Instead of repeating this string in every example, it will be put into a file which will be included by each example. This include file is shown in the following example section. Alternatively, you could create an XML document and read it with DomDocument_open_file().

Przykład 1. Include file example.inc with XML string

<?php
$xmlstr
= "<?xml version='1.0' standalone='yes'?>
<!DOCTYPE chapter SYSTEM '/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd'
[ <!ENTITY sp \"spanish\">
]>
<!-- lsfj  -->
<chapter language='en'><title language='en'>Title</title>
<para language='ge'>
  &sp;
  <!-- comment -->
  <informaltable ID='findme' language='&sp;'>
   <tgroup cols='3'>
    <tbody>
     <row><entry>a1</entry><entry
morerows='1'>b1</entry><entry>c1</entry></row>
<row><entry>a2</entry><entry>c2</entry></row>
     <row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
    </tbody>
   </tgroup>
  </informaltable>
</para>
</chapter>"
;
?>

Spis treści
DomAttribute->name --  Returns the name of attribute
DomAttribute->set_value --  Sets the value of an attribute
DomAttribute->specified --  Checks if attribute is specified
DomAttribute->value --  Returns value of attribute
DomDocument->add_root --  Adds a root node [deprecated]
DomDocument->create_attribute -- Create new attribute
DomDocument->create_cdata_section -- Create new cdata node
DomDocument->create_comment -- Create new comment node
DomDocument->create_element_ns --  Create new element node with an associated namespace
DomDocument->create_element -- Create new element node
DomDocument->create_entity_reference --  Create an entity reference
DomDocument->create_processing_instruction -- Creates new PI node
DomDocument->create_text_node -- Create new text node
DomDocument->doctype --  Returns the document type
DomDocument->document_element --  Returns root element node
DomDocument->dump_file --  Dumps the internal XML tree back into a file
DomDocument->dump_mem --  Dumps the internal XML tree back into a string
DomDocument->get_element_by_id --  Searches for an element with a certain id
DomDocument->get_elements_by_tagname --  Returns array with nodes with given tagname in document or empty array, if not found
DomDocument->html_dump_mem --  Dumps the internal XML tree back into a string as HTML
DomDocument->xinclude --  Substitutes XIncludes in a DomDocument Object
DomDocumentType->entities() --  Returns list of entities
DomDocumentType->internal_subset() --  Returns internal subset
DomDocumentType->name() --  Returns name of document type
DomDocumentType->notations() --  Returns list of notations
DomDocumentType->public_id() --  Returns public id of document type
DomDocumentType->system_id() --  Returns the system id of document type
DomElement->get_attribute_node() --  Returns the node of the given attribute
DomElement->get_attribute() --  Returns the value of the given attribute
DomElement->get_elements_by_tagname() --  Gets elements by tagname
DomElement->has_attribute() --  Checks to see if an attribute exists in the current node
DomElement->remove_attribute() --  Removes attribute
DomElement->set_attribute_node() --  Adds new attribute
DomElement->set_attribute() --  Sets the value of an attribute
DomElement->tagname() --  Returns the name of the current element
DomNode->add_namespace --  Adds a namespace declaration to a node
DomNode->append_child --  Adds a new child at the end of the children
DomNode->append_sibling --  Adds new sibling to a node
DomNode->attributes --  Returns list of attributes
DomNode->child_nodes --  Returns children of node
DomNode->clone_node --  Clones a node
DomNode->dump_node --  Dumps a single node
DomNode->first_child --  Returns first child of node
DomNode->get_content --  Gets content of node
DomNode->has_attributes --  Checks if node has attributes
DomNode->has_child_nodes --  Checks if node has children
DomNode->insert_before --  Inserts new node as child
DomNode->is_blank_node --  Checks if node is blank
DomNode->last_child --  Returns last child of node
DomNode->next_sibling --  Returns the next sibling of node
DomNode->node_name --  Returns name of node
DomNode->node_type --  Returns type of node
DomNode->node_value --  Returns value of a node
DomNode->owner_document --  Returns the document this node belongs to
DomNode->parent_node --  Returns the parent of the node
DomNode->prefix --  Returns name space prefix of node
DomNode->previous_sibling --  Returns the previous sibling of node
DomNode->remove_child --  Removes child from list of children
DomNode->replace_child --  Replaces a child
DomNode->replace_node --  Replaces node
DomNode->set_content --  Sets content of node
DomNode->set_name --  Sets name of node
DomNode->set_namespace --  Sets namespace of a node
DomNode->unlink_node --  Deletes node
DomProcessingInstruction->data --  Returns the data of ProcessingInstruction node
DomProcessingInstruction->target --  Returns the target of a ProcessingInstruction node
DomXsltStylesheet->process() --  Applies the XSLT-Transformation on a DomDocument Object
DomXsltStylesheet->result_dump_file() --  Dumps the result from a XSLT-Transformation into a file
DomXsltStylesheet->result_dump_mem() --  Dumps the result from a XSLT-Transformation back into a string
domxml_new_doc --  Creates new empty XML document
domxml_open_file -- Creates a DOM object from an XML file
domxml_open_mem -- Creates a DOM object of an XML document
domxml_version --  Gets the XML library version
domxml_xmltree --  Creates a tree of PHP objects from an XML document
domxml_xslt_stylesheet_doc --  Creates a DomXsltStylesheet Object from a DomDocument Object
domxml_xslt_stylesheet_file --  Creates a DomXsltStylesheet Object from an XSL document in a file
domxml_xslt_stylesheet --  Creates a DomXsltStylesheet object from an XSL document in a string
domxml_xslt_version --  Gets the XSLT library version
xpath_eval_expression --  Evaluates the XPath Location Path in the given string
xpath_eval --  Evaluates the XPath Location Path in the given string
xpath_new_context --  Creates new xpath context
xpath_register_ns_auto --  Register the given namespace in the passed XPath context
xpath_register_ns --  Register the given namespace in the passed XPath context
xptr_eval --  Evaluate the XPtr Location Path in the given string
xptr_new_context --  Create new XPath Context



WÄ…tki z forum o php

Najnowsze posty naszych userów

nie w³±cza sie ca³kowicie instalator systemu win xp.
witam, chcê mojej dziewczynie sformatowaæ komputer, po ustawieniu kolejno¶ci bootowania, resetuje komputer, wk³adam plyte z windowsem, i pojawia sie czarny ekran z informacja, ze wlacza sie instalator windows, potem pojawia sie niebeiski ekran z napisem instalator rozpakowywuje pliki i wtym momencie komputer staje, dysk przestaje sie krecic i naped tez, cos jakby zawieszka, dzieje sie to zarowno w przypadku winxp 1 wer. jak i ta z sp2. prosze o pomoc,

plyta glowna ECS, proc. Athlon 1GHz.
dual layer czy Double layer
Witam


Patrzê w everest jakie p³yty obs³uguje moja nagrywarka dvd.I przy jednej opcji pisze DVD+R9 Dual Layer czym¶ siê rózni od duble layer?I czy mogê kupiæ p³ytki duble layer aby je nagraæ? czy musz± byæ dual layer



Kaszanka dobra do wszystkiego [+18]
Drogie Bravo, drodzy koledzy i kole¿anki.Mam na imiê Dagmara i mam 19 lat. Moja sytuacja jest bardzo krepuj±ca i nie wiem co teraz mam zrobiæ. Jestem ju¿ doros³± dziewczyn± i mam wspania³ego ch³opaka o imieniu Marcin, którego kocham ponad ¿ycie i my¶lê ze on odwzajemnia moje uczucie. Jeste¶my ju¿ razem 6 miesiêcy i postanowili¶my dokonaæ Aktu Mi³osnego, aby umocniæ nasz zwi±zek. Nie fart polega na tym ¿e ja jestem dziewic±, a z tego co wiem On jest ju¿ do¶wiadczonym mê¿czyzn±. Bardzo obawia³am siê ¿e nie spe³niê jego oczekiwa , po prostu zawiodê! Na dodatek wszystkie moje kole¿anki potraci³y ju¿ dziewictwo i ¿eby mieæ o czym rozmawiaæ z nimi, powiedzia³am ¿e ja równie¿ nie jestem jak to siê mówi potocznie "cnotk±". O tym fakcie dowiedzia³ siê Marcin od mojej kole¿anki, Moniki, która jest jego dobr± znajom±. Gdy Marcin zapyta³ czy to prawda nie zaprzeczy³am. Ustalili¶my nasz Pierwszy Raz na najbli¿szy weekend, poniewa¿ Marcina rodzice jad± na wesele. Bardzo siê obawia³am bólu, oraz tego ¿e Marcin pos±dzi mnie o k³amstwo, wiêc postanowi³am jako¶ sobie poradziæ. Nie chcia³am przespaæ siê z "pierwszym lepszym" gdy¿ kocham Marcina i chcê aby to on by³ moim Pierwszym Mê¿czyzn±!! Akurat zdarzy³o siê tak ¿e by³am sama w domu i postanowi³am uporaæ siê z moja b³ona dziewicz±. Nie chcia³am robiæ tego palcami ani jakim¶ twardym przedmiotem a na wibrator niestety nie by³o by mnie staæ. Posz³am wiêc do lodówki i zobaczy³am nadaj±c± siê do mojego czynu kaszankê. Odpowiada³a mi rozmiarem i grubo¶ci±, by³a trochê za zimna i za twarda wiêc postanowi³am ja podgotowaæ. Kiedy nareszcie ostyg³a, nasmarowa³am ja wazelin±, i zaczê³am wk³adaæ j± do pochwy. Podda³am siê chyba za bardzo chwili i za bardzo j± ¶cisnê³am. Wtedy sta³o siê najgorsze co mog³o siê staæ!! KASZANKA SIÊ Z£AMA£A!!!!!!!!!!Rozpaczliwie próbowa³am j± wyj±æ palcami ale chyba trochê za bardzo j± rozgotowa³am i niektóre kawa³ki kaszanki zosta³y mi w pochwie i nie mogê ich wyj±æ! Wstydzê siê i¶æ do ginekologa a za kilka dni wyczekiwany przez nasz± dwójkê upojny weekend!! Nie wiem co mam zrobiæ i do kogo siê zwróciæ. Co teraz pomy¶li o mnie Marcin!! B£AGAM POMÓ¯CIE!!!!!
Zrozpaczona

Odpowied¼ Bravo:
Na wstêpie pragniemy podziêkowaæ Ci za podzielenie siê z nami swoim problemem. W twojej nader ciekawej sytuacji proponujemy Ci dwa rozwi±zania:
1. Ekstrawaganckie w stylu new art.
2. Si³owe

Pierwsze wydaje nam siê ciekawe lecz mo¿e nie przynie¶æ spodziewanych efektów. Musisz pokroiæ cebulê w kostkê, a nastêpnie podsma¿yæ j± na z³ocisty kolor na patelni (koniecznie na oleju z pierwszego tloczenia). Nastêpnie musisz dopchaæ j± do pochwy i zrobiæ 3-4 przysiadów tak aby zmiesza³a siê z kaszank±. Potem zapro¶ swojego ukochanego na romantyczne spotkanie inicjuj±ce. Przed pierwszym stosunkiem zaproponujesz mu wiêc kaszankê po staropolsku w wersji francuskiej. W ten sposób osi±gniesz dwa cele: udowodnisz mu, ¿e bardzo go kochasz i jednocze¶nie poka¿esz, ¿e ¶wietnie gotujesz. Przypominamy Ci powiedzenie "PRZEZ ¯O£¡DEK DO SERCA".

Rozwi±zanie drugie jest jednak o wiele bardziej skuteczne. Przygotuj patelniê na której mia³a¶ zarumieniæ cebulkê. Nastêpnie we¼ j± w praw± rêkê (je¶li jeste¶ leworêczna to w lew±) i [beeep]nij siê ni± z ca³ej si³y w g³owê - bo tobie to ju¿ chyba nic nie pomo¿e!
Z powa¿aniem Redakcja


Problemem bylo to, ze autor nie pozostawil mozliwosci zmian, wiec za pomoca programu PHP WebPage Editor zmienilem pewne potrzebne mi wartosci (ilosci wojsk - to akurat bylo latwe do znalezienia...), ale nie wiem, ktore wartosci odpowiadaja za czas wysylania tych jednostek wojska - chce zmienic z tych kilkunastu sekud na ok 1,5 godz... (to dziwne, bo nie jest to regularne - niektore ataki wychodza co 10 sek, niektore co 15 albo 20.