Results 1 to 5 of 5

Thread: read xml file

  1. #1
    Join Date
    Feb 2009
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default read xml file

    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?

  2. #2
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    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?

  3. #3
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No...
    SimpleXML.

    Are you making a xml login? Here's a nice video tutorial on how to do that.

    Quite Simple.
    Jeremy | jfein.net

  4. #4
    Join Date
    Feb 2009
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Yes Nile, I use PHP and I want to display the same source code. And also want to read it line by line.

  5. #5
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    This should work:
    PHP Code:
    <?php
    $xml 
    = new SimpleXMLElement("file.xml"0true);

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •