A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
How to read XML using PHP DOMThis tutorial will demonstrate the use of DOM extension in PHP to read contents of a XML file. |
On Thursday, December 29th 2005 at 02:24 PM By Nabeel Akhtar (View Profile) ![]() ![]() ![]() ![]() (Rated 4.1 with 68 votes) |
||
|
This tutorial is for PHP starters as well as for those who are using XML parser functions to read/write XML files. This tutorial will not go into details on XML. The focus will be more on the Document Object Model (DOM) extension.
<?
The output on your webpage will be something like this: Validate data :: Validate data in SQL2005 Database with SQL manager Download Music :: Download latest music from site abc I have documented some of the built-in functions in the code. For more details please refer to the php manual. This tutorial is a kick start for beginners. You can retreive data from a database and create a XML document on-the-fly with DOM functions, rename tabs in an existing XML document and validate format. |
|||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||
|
|||
Current Commentsit doesn\'t work.... Parse error: syntax error, unexpected T_OBJECT_OPERATOR in .... on line 17
the code works on php v5 but not on lower versions by the sounds of things.
I am wondering how to get the attributes out of the elements, such as the xml version and encoding in the xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
thanks
This is a nice example to know about basic XML.
Thanks.
sfgsgsgsg sg sdfgsfgsf
PHP XML DOM tutorial very clear and easy
I want to add one more attribute in the existing tag.
Is there a way in php
This was awesome, it got me going right away. I actually took a huge xml file and was able to parse it with your code. Today is my first day learning xml.
etrett teeet retert etertre retertet ter
not working, got no luck, same as mustafa did. syntax error, unexpected T_OBJECT_OPERATOR
this is very nice Example. from above example i hv just created a file and place <a></a> between specific text , but in output no link is displayed.. how to put it??
this is very nice Example. from above example i hv just created a file and place <a></a> between specific text , but in output no link is displayed.. how to put it??
really nice. Lets try it and see :)
This is very simple example and nice
not working ....
gives a blank page as output.. plz help ... all though it works with SAX parser but the code to write in sax parser is too long... how to read and print from XML using dom...
it'a very nice understand
this code is good and its working...but
when there is code like
<link rel="alternate" href ="www.example.com" />
then how to obtain the value of rel, href ???????
please do reply m eager waiting for answer
i use <a href="yourpage.php?something=alternate>
Where alternate can be any value that you want to pass to the other page.
then get the value by a
$your_variable = $_GET['something'];
THANKS for this tutorial. Needed some of the inormation here
This script was very helpful ...
its awesome..thanks
this tutorial got me up to speed with my coursework. was stuck now i can move on. thanks so much
how to get the attribute values of the xml file using php...
thanks in advance
it is very nice and clear example for bigginers
Excellent tutorial. Thanks!
Any reference to advanced ones with ways to get attributes in xml would be very helpful
Thanks so much!.. This worked right away!.. and saved me many hours of work!!! :o)
how to read an xml file stored in mysql database, extract the contents from its multiple nodes n store it in the mysql database?????????
help me out.......
syntax error, unexpected T_OBJECT_OPERATOR
thanks a lot.........
but still i've a doubt.....
how can i retrieve the xml file if it is stored in a mysql databse????????
hi........
how to check whehter an alement exists in a xml file using dom xml in php........
hi........
how to check whehter an element exists in a xml file using dom xml in php........
very good tutorial. thanks.
if there is one more tag <note1> then how should i do? please
superb :-)
I'm trying to parse out the "H458232" following bit between these two tags, but it doesn't work:
<contact:id>H458232</contact:id>
Possibly because there are other <contact:> type tags, eg <contact:address> etc.
How can I select just the one I need?
Thanks
great work awesome
great work awesome
how to write this xml using PHP plz help me:--
<mix backFname='C:\My Documents\DataMax News\News.MP3\_Tracks\News_2_Score.mp3'
areaStart='0.309'
areaEnd='79'
minSpace='0.5'
maxSpace='4.0'
autoRemove='fromEnd'
backVol='1'
duckVol='0.15'
duckPre='0.10'
duckPost='0.3'
encodeCmd='lame -b 128 - "C:\My Documents\DataMax News\News.MP3\News_2\News.mp3"'
>
<dir fname='C:\My Documents\DataMax News\News.MP3\Pool_2\news*.mp3' />
</mix>
how to write this xml using PHP plz help me:--
<mix backFname='C:\My Documents\DataMax News\News.MP3\_Tracks\News_2_Score.mp3'
areaStart='0.309'
areaEnd='79'
minSpace='0.5'
maxSpace='4.0'
autoRemove='fromEnd'
backVol='1'
duckVol='0.15'
duckPre='0.10'
duckPost='0.3'
encodeCmd='lame -b 128 - "C:\My Documents\DataMax News\News.MP3\News_2\News.mp3"'
>
<dir fname='C:\My Documents\DataMax News\News.MP3\Pool_2\news*.mp3' />
</mix>
how to write this xml using PHP plz help me:--
<mix backFname='C:\My Documents\DataMax News\News.MP3\_Tracks\News_2_Score.mp3'
areaStart='0.309'
areaEnd='79'
minSpace='0.5'
maxSpace='4.0'
autoRemove='fromEnd'
backVol='1'
duckVol='0.15'
duckPre='0.10'
duckPost='0.3'
encodeCmd='lame -b 128 - "C:\My Documents\DataMax News\News.MP3\News_2\News.mp3"'
>
<dir fname='C:\My Documents\DataMax News\News.MP3\Pool_2\news*.mp3' />
</mix>
very good tutorial for beginners.
thanks
http://shri.com.np
Rajiv, I believe this is how you make your xml doc.
$xmlDoc = new DomDocument('1.0');
$mainNode = $xmlDoc->createElement('mix');
$mainNode = $xmlDoc->appendChild($mainNode);
$mainNode->setAttribute('backFname', 'C:\My Documents\DataMax News\News.MP3\_Tracks\News_2_Score.mp3');
$mainNode->setAttribute('areaStart', '0.309');
$mainNode->setAttribute('minSpace', '0.5');
$mainNode->setAttribute('maxSpace', '4.0');
$mainNode->setAttribute('autoRemove', 'fromEnd');
$mainNode->setAttribute('backVol', '1');
$mainNode->setAttribute('duckVol', '0.15');
$mainNode->setAttribute('duckPre', '0.10');
$mainNode->setAttribute('duckPost', '0.3');
$mainNode->setAttribute('encodeCmd', 'lame -b 128 - "C:\My Documents\DataMax News\News.MP3\News_2\News.mp3"');
$innerNode = $xmlDoc->createElement('dir');
$innerNode = $mainNode->appendChild($innerNode);
$innerNode->setAttribute('fname','C:\My Documents\DataMax News\News.MP3\Pool_2\news*.mp3');
$xmlDoc->save("xmlDoc.xml");
Excellent Tutorial thanks. But an error thrown for an no content. Document is empty
Excellent Tutorial thanks. But an error thrown for an no content. Document is empty
Error : DOMDocument::load() [function.DOMDocument-load]: Document is empty
<?xml version="1.0" encoding="ISO-8859-1"?>
<mynotes>
<note>
<tasks>Validate data</tasks>
<details>Validate data in SQL2005 Database with SQL manager</details>
</note>
<note>
<tasks>Download Music</tasks>
<details>Download latest music from site abc</details>
</note>
</mynotes>
if from this xml file i want to take only the elements from the first <note></note> what i have to do.
Here, I got easy understanding code,...
thanq very much.
good one for beginners
nd ddd
nd ddd
$xmlDoc = new DomDocument('1.0');
$mainNode = $xmlDoc->createElement('mix');
$mainNode = $xmlDoc->appendChild($mainNode);
$mainNode->setAttribute('backFname', 'C:\My Documents\DataMax News\News.MP3\_Tracks\News_2_Score.mp3');
$mainNode->setAttribute('areaStart', '0.309');
$mainNode->setAttribute('minSpace', '0.5');
$mainNode->setAttribute('maxSpace', '4.0');
$mainNode->setAttribute('autoRemove', 'fromEnd');
$mainNode->setAttribute('backVol', '1');
$mainNode->setAttribute('duckVol', '0.15');
$mainNode->setAttribute('duckPre', '0.10');
$mainNode->setAttribute('duckPost', '0.3');
$mainNode->setAttribute('encodeCmd', 'lame -b 128 - "C:\My Documents\DataMax News\News.MP3\News_2\News.mp3"');
$innerNode = $xmlDoc->createElement('dir');
$innerNode = $mainNode->appendChild($innerNode);
$innerNode->setAttribute('fname','C:\My Documents\DataMax News\News.MP3\Pool_2\news*.mp3');
$xmlDoc->save("xmlDoc.xml");
<a href="www.google.com">google</a>
Thanx it worked for me...
I have a litle one for you all this worked but i have an ell. that has a name like this
<player name="the name">
how would i get the name info to display?
would love the help thank you...
Thanks for the script it works perfectly on my test server using php5 but my live server is a lower version. . . . any ideas on how i can change the script to make it work?
Thanks
Mario
how i can read xml file and print same file in browser
please reply me fast
Very well written...saved me a lot of work!
Mapper
http://www.freegooglewaveinvites.com
this is very usefull example for the biggnerrs
Worked first time. Thanks!
I got this Error
Fatal error: Call to undefined method DOMElement::item() in D:\xampp\htdocs\pc3\SMS\citisms\tryxml.php on line 16
Help me
I got this Error
Fatal error: Call to undefined method DOMElement::item() in D:\xampp\htdocs\pc3\SMS\citisms\tryxml.php on line 16
Help me
Thanks is works.
But i have a problem.
In my xml file i have
<event type="2" id="123456">
</event>
how to read that?
thanks man.But i m not getting how
$tasks = $value->getElementsByTagName("name");
$task = $tasks->item(0)->nodeValue; works???
please send me reply on mail
Thanks,it levels the ground 4 me
Thanks,it levels the ground 4 me
i have just read it, it seems very usefull, i will let you know about my experience..
thanks for helping..
It works. I had to mod it a little, but now i've added a lot of other functions. Thanks!
Thank you it's really helpfull!
Damn, this thing subscribed me to comments.. Why isn't there a button [UnSubscribe] ??? :(
Damn, this thing subscribed me to comments.. Why isn't there a button [UnSubscribe] ??? :(
Different people in the world receive the <a href="http://lowest-rate-loans.com/topics/personal-loans">personal loans</a> from various creditors, because it's comfortable and fast.
What you say - Butter or cream? Anyways this script runs smoother than that.
What you say - Butter or cream? Anyways this script runs smoother than that.
Thanks. After trying loads of different XML parsers yours was the first that actually worked.
how replace $objDOM->load("test.xml"); in php 5 where allow_url_open is disabled? thanks in advance
For those of you that are confused as to how to get the attr of an XML node.
Read this page:
http://www.php.net/manual/en/domelement.getattribute.php
It explains how to obtain the attr value of a DOM node.
2 seconds on Google... *Sigh*
2 secs?
sure, but that isn't the right solution, if none tells you to use loadXML function...
xp, it's assumed knowledge.
this stuff is pretty helpful
this stuff is pretty helpful
how to edit and delete xml node in file.
pls tell me
how to edit and delete xml node in file.
pls tell me
how to edit and delete xml node in file.
pls tell me
Nice
good work
Related Tutorials
Related Source Code
PHP Job Search