Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

DOM XML: An Alternative to Expat
The Objects Used In DOM
At this point, you are probably wondering what is a DomNode. This is a good place to start talking about the objects that are included in the module. There are five objects defined by DOM: DomDocument, DomNode, DomAttribute, DomDtd, and DomNamespace. We are going to be focusing primarily on the DomDocument and DomNode objects because they are the most useful.
The Node object
Here is an overview of what the DomNode object contains.
class DomNode
	properties:
		name
		content
		type
	methods:
		lastchild() 
		children() 
		parent() 
		new_child( $name,$content ) 
		getattr( $name ) 
		setattr( $name,$value ) 
		attributes() 
The properties need some elaboration.
  • The name property is the actual tag name of the node. A node which refers to the the title tags would have the name of 'title'.
  • The content property is usually empty. However, text nodes use this property to hold text.
  • The type property is a constant which defines exactly what kind of object the node is. There can be several types of DomNode objects. A list of constants are online at http://www.php.net/manual/ref.domxml.php. For example, a DomNode containing text would have a type of XML_TEXT_NODE.
The methods need to be explained, as well.
  • lastchild() returns the last entry from a node's children.
  • parent() returns a node's parent. For instance, the parent of our title node would be 'book'.
  • children() returns an array of a node's child nodes. For example, the children of node author would be 'name' and 'birthdate'.
  • new_child() takes a name and some content as arguments and adds a new DomNode to its children.
  • getattr() and setattr() both deal with attributes. One fetches the value, the other sets it.
  • attributes() returns an array of DomAttribute objects.
The DomDocument object
The DomDocument object is also important.
class DomDocument
	properties:
		version 
		encoding 
		standalone
		type
	methods:
		root() 
		children() 
		add_root( $node ) 
		dtd() 
		dumpmem() 
The properties are pretty self explanatory.
  • 'version' refers to the xml version of the document.
  • 'encoding' refers to the text encoding.
  • 'standalone' is a boolean value determining whether the document is standalone or not.
  • The 'type' property has already been explained. A Document object will most likely have the type of XML_DOCUMENT_NODE.
The methods are pretty simple too.
  • root() returns the root node of a document. If we loaded our sample xml file as a DomDocument object, the root node would refer to 'book'.
  • children() works just as it did in DomNode.
  • add_root() adds a new root node to the xml document. You would use this if you wanted to supplant the 'book' node with another node.
  • dtd() returns the xml document's dtd.
  • dumpmem() returns a string representation of the xml data.
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
PHP5 DOM TEMPLATE ENGINESimon Jackson10/03/08 02:36
how to install libxml2Anjali01/07/05 04:52
succesfully Enabling DOM using phpTriad W32Arturo Cobos05/18/03 18:38
RE: intalling sablotron YinD02/13/03 04:40
RE: DOM with IISskynet01/06/03 18:36
intalling sablotron mounir10/08/02 05:54
RE: Error calling DOMXML function under WindoMads Østerby10/07/02 04:37
Error calling DOMXML function under Windowslian09/16/02 18:20
accessing second XML file from in xslAmrit Lalli08/23/02 16:15
DOM with IISDavid08/03/02 13:02
loading in a string vs. fileDenise07/22/02 14:08
RE: Adding xml-stylesheet tag? Ross Golder07/11/02 17:35
appending and saveallen coombs07/05/02 09:51
Add a multiLine and special characters nodeTitouille07/02/02 11:05
RE: Failed to load external entity.Paulo06/25/02 13:23
XML DOM helpBen06/14/02 08:50
help sos!dysow06/09/02 23:00
RE: Installing DOMXML under WindowsGeorge Yun06/02/02 23:12
Installing DOMXML under Windows with iis5why05/30/02 22:39
installing DOMXML problemGeorge Yun05/30/02 20:54
domxml_xslt_process problem !?!?Claudiu Balanean05/27/02 09:37
RE: Problem with node->set_contentRob Richards05/18/02 10:04
RE: Deleting a forumsam05/17/02 00:23
Problem with node->set_contentMirax05/16/02 08:20
Correction of example on page 4 for PHP 4.2.0Vlado S.05/13/02 10:20
XML DOMmichel05/05/02 11:14
XML DOMmichel05/05/02 11:13
Sample to change or add dataChristiaan Schaake04/29/02 10:16
RE: Error loading DOM XMLYogesh Randhawa04/26/02 02:38
RE: Error loading DOM XMLDjango Janny04/25/02 04:14
Failed to load external entity.Deke04/25/02 04:11
tutorial does not work?Christian04/24/02 08:19
Adding xml-stylesheet tag? Robert Strand04/22/02 05:30
RE: <![CDATA[ A ]]> : Urgent help neededemthanh04/18/02 12:38
RE: Installing DOMXML under WindowsMads Østerby04/15/02 12:51
And about performances ?ThM04/11/02 16:51
no nmake... can't install libxml... help?Rudolf Vavruch04/03/02 10:27
RE: DOM/XML & PHP 4.1.XBes03/28/02 16:54
RE: DOM/XML & PHP 4.1.XGal03/25/02 08:51
RE: DOM/XML & PHP 4.1.XGal03/24/02 07:27
RE: Installing DOMXML under WindowsGeorge02/26/02 14:15
CDATA How ?jack3483@ifrance.Com02/14/02 09:02
RE: Finding libxml-2.2.7Kalpix02/08/02 02:11
Overhead of node deletionssiva02/06/02 22:24
DOM/XML & PHP 4.1.XJoe Thielen02/04/02 22:15
RE: Error loading DOM XMLMac Martine01/30/02 01:05
RE: Error loading DOM XMLMac Martine01/30/02 01:04
PHP & IIS, Win2kzman01/29/02 15:15
children of child node??Sandeep Murthy01/23/02 05:39
Differences with PHP 4.1.1 ?Philippe Langlois01/21/02 02:20
RE: insert node from one object into another?Dietmar Glachs12/20/01 03:49
RE: Installing DOMXML under WindowsMads Østerby12/19/01 10:29
want Example add,delete,insert and updateThai Girl12/17/01 05:24
RE: Installing DOMXML under WindowsHaris12/14/01 03:15
<![CDATA[ A ]]> : Urgent help neededRahul12/08/01 09:02
RE: DOM does work with php4.0.6 in WindowsThomas Wasserberg12/04/01 06:15
XSL transformation supportRichard Borrie11/28/01 07:47
RE: Installing DOMXML under WindowsMads Østerby11/25/01 14:37
RE: How to put xml data into database?Antonio Carvalho11/20/01 05:00
RE: insert node from one object into another?Arne Blankerts11/14/01 06:51
Problem with PHP 4.0.6 under WindowsHans Hagmann11/06/01 02:26
DOM does work with php4.0.6 in WindowsCathy10/30/01 06:36
RE: DOM does not work anymore in newer PHP'sCathy10/30/01 04:53
DOM does not work anymore in newer PHP'sMelvin10/26/01 04:56
Finding libxml-2.2.7Cathy10/19/01 07:40
RE: Installing DOMXML under WindowsMax Zilla10/14/01 05:31
RE: Installing DOMXML under Windowsmaxzilla10/04/01 09:56
wondelful for DOM referencemuruganselvaraj09/27/01 04:17
returning XPath resultsDaniel Allen09/01/01 04:58
RE: ![CDATA[ ]]Jean-Charles Preaux08/29/01 04:31
RE: Installing DOMXML on Windows!igor stuyver08/15/01 09:36
RE: Installing DOMXML under WindowsTomcio08/01/01 20:55
Error loading DOM XMLTom08/01/01 19:06
RE: Deleting a nodeChristophe RISCH07/30/01 07:20
Very Good Tutorialjan janssen07/20/01 05:38
RE: Deleting a nodeThomas Schädler05/27/01 03:18
![CDATA[ ]]Olivier Le Roy05/25/01 06:49
DOMXML an NamespacesBerhard Zwischenbrugger 05/07/01 09:05
PHP 4.0.5 and DOMSylvain B05/07/01 02:43
RE: xpath_eval functionDietmar04/20/01 06:46
xpath_eval functionVincenzo04/13/01 08:30
Adding a new nodeDominique Paquin03/30/01 15:00
RE: Deleting a nodeDietmar03/27/01 07:16
RE: Deleting a nodethor03/21/01 09:38
RE: Just one problem - Character supportBobbisson03/13/01 12:38
RE: insert node from one object into another?Dietmar Glachs03/09/01 07:21
RE: Set content / delete a nodeDominique Paquin03/08/01 10:07
insert node from one object into another?Hauke Haastert03/07/01 09:59
RE: Set content / delete a nodejagan kommineni03/06/01 20:17
InformativeMohanraj02/28/01 21:43
Installing DOMXML on Windows!Mads Østerby02/24/01 10:36
Installing DOMXML under WindowsMads Østerby02/24/01 10:30
RE: How to put xml data into database?Stuart Begg02/20/01 20:48
Set content / delete a nodeStuart Begg02/20/01 20:11
RE: Deleting a nodeDietmar Glachs02/12/01 00:45
RE: Deleting a nodeJody Nickel02/08/01 20:24
XPathDaniel Fairs02/05/01 04:23
How to put xml data into database?kevin zhang02/01/01 21:57
Just one problem - Character supportLuis Oliveira01/31/01 13:28
commentsR. Yuvaraju01/29/01 10:50
RE: new DOM features im 4.0.4peter sabaini01/29/01 06:55
textnodes into existing nodeRobin Gruyters01/24/01 08:59
Great ArticleNavid Yar01/23/01 05:49
insert a node above another one.n000b01/17/01 23:02
Deleting a nodeJens Wabnitz01/15/01 12:35
RE: Changing node's contentJohn Plato01/15/01 04:16
Changing node's contentSergey Kanareykin01/09/01 17:24
Page Display ProblemTac01/08/01 09:53
Choice of Method & Property Namesterry chay01/04/01 19:14
PHP 4.0.4, DOMXML, & Memoryterry chay01/04/01 18:59
new DOM features im 4.0.4Luis Argerich01/02/01 06:40
Very coolLuis Oliveira01/01/01 17:28
RE: Portability issueRalf Weber12/29/00 09:56
Portability issuePaul Meagher12/28/00 11:50
Some Problems I see/haveOliver Kurz12/28/00 10:14
very interestingKevin Monroe12/28/00 08:18
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.