Log in

View Full Version : read xml file



lay
03-12-2009, 02:52 AM
I have one xml file that have the format like this :

<?xml version="1.0" encoding="UTF-8" ?>
<Userpwd>
<login id="1">
<username>titi</username>
<password>123456</password>
</login>
<login id="2">
<username>4clajdkfjd</username>
<password>jjjjjjjjjjjjjh</password>
</login>
</Userpwd>

and I want to read and display it.
Can you help me?:)

magicyte
03-12-2009, 02:55 AM
Which language would you like to use? PHP? Simply use fopen("filehere.xml", "r"); to open it. Then you can manipulate it some other way... How do you want to display it?

Nile
03-12-2009, 03:04 AM
No...
SimpleXML. (http://us.php.net/simplexml)

Are you making a xml login? Here's (http://net.tutsplus.com/videos/screencasts/build-a-login-and-registration-system-with-xml/) a nice video tutorial on how to do that.

Quite Simple.

lay
03-12-2009, 05:10 AM
Yes Nile, I use PHP and I want to display the same source code. And also want to read it line by line.

Nile
03-12-2009, 12:13 PM
This should work:


<?php
$xml = new SimpleXMLElement("file.xml", 0, true);

foreach($xml->login as $user){
echo "User Login #".$user->attributes()."<br />
<ul>
<li>User: ".$user->username."</li>
<li>Pass: ".$user->password."</li>
</ul>";
}
?>