SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Very Basic XML

Hybrid View

  1. #1
    SitePoint Evangelist JordashTalon's Avatar
    Join Date
    Dec 2008
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Very Basic XML

    I have an XML file like this

    <varname>varvalue</varname>

    saved as filename.xml

    How would I get the all of the varnames into variables in PHP?

    Thanks

  2. #2
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is probably not a valid xml file.
    You should have only one root element in the xml file, then under the root you can put all your varname elements.

    Then just use SimpleXML to parse your file.
    look at this page:
    http://us.php.net/manual/en/function...-load-file.php

    It's hard to write an example because I don't know all the details, for example. do you know in advance which varnames you will have in the xml?

    It's pretty simple either way.

  3. #3
    SitePoint Evangelist JordashTalon's Avatar
    Join Date
    Dec 2008
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so probably like this:

    <variables>
    <varname>text text</varname>
    <varname1>text text</varname1>
    </variables>

  4. #4
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JordashTalon View Post
    so probably like this:

    <variables>
    <varname>text text</varname>
    <varname1>text text</varname1>
    </variables>
    Well, yes, that's better. If you going to store this in a file, you should add this to the top of file (it should be the very first line)

    <?xml version="1.0"?>

  5. #5
    SitePoint Evangelist JordashTalon's Avatar
    Join Date
    Dec 2008
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That helped I read through that link you gave me and looks like PHP has some sweet XML reading functions I did this

    $variables=simplexml_load_file('variables.xml');

    echo 'Variable One: ' . $variables->varname;

    and that will do exactly what I need,

    Thanks for the help!


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
  •