HI
I need to convert xml node value into string. I am using
$file = file_get_contents("test.xml");
But i am getting whole xml file into string. I want only particular node value into string..
Thanks in advance
Convert XML node value into string
Moderator: General Moderators
-
sathyaparthi
- Forum Newbie
- Posts: 7
- Joined: Fri Jul 09, 2010 12:06 am
-
patel.manjeet
- Forum Newbie
- Posts: 4
- Joined: Mon Jul 12, 2010 5:17 am
Re: Convert XML node value into string
Hi,
to read some node text u need to read XML file using php.
simple method to read XML in php is SimpleXML. Some sample code to read XML ..hope may useful ..
test.xml file
PHP Code
to read some node text u need to read XML file using php.
simple method to read XML in php is SimpleXML. Some sample code to read XML ..hope may useful ..
test.xml file
Code: Select all
<?xml version='1.0'?>
<document>
<title>Forty What?</title>
<from>Joe</from>
<to>Jane</to>
<body>
I know that's the answer -- but what's the question?
</body>
<desc>
<other>otherinfo1</other>
<data>datainfo1</data>
</desc>
</document>
PHP Code
Code: Select all
$filename = 'test.xml'; // xml file path/ url
$xml = simplexml_load_file ($filename);
echo $xml->title; // Forty What?
echo $xml->desc->other; // otherinof1