PHP and XML help

Discussion in 'Web Design and Development' started by italiano40, Sep 8, 2008.

  1. italiano40 macrumors 65816

    italiano40

    Joined:
    Oct 7, 2007
    Location:
    NY
    #1
    a couple things
    one i just start writing in php, but i know html, css, java, C++, Cocoa
    and i want to know what is the best way to pase
    a xml document, also in php is their something like null
    i couldn't find anything about it
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    For parsing XML I generally treat it as a DOM document:
    PHP:
    $doc = new DomDocument();
    $doc->load("your.xml");
    $tags $doc->getElementsByTagName("tag");
    There's also Simple XML:
    PHP:
    $doc simplexml_load_file('your.xml');
    PHP null.
     
  3. italiano40 thread starter macrumors 65816

    italiano40

    Joined:
    Oct 7, 2007
    Location:
    NY
    #3
    ok, it i wanted to go thru each tag which one would you recommend the simple xml or treat as dom?
     
  4. angelneo macrumors 68000

    Joined:
    Jun 13, 2004
    Location:
    afk
    #4
    Personally I prefer DOM. Simple XML, I believe, requires PHP 5.
     
  5. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #5
    I prefer DOM because I work with JavaScript a bit so I'm use to thinking that way. Simple XML has some power over DOM in some instances though. I suggest doing some reading on articles that compare the two approaches so you can decide which will best suit the work your doing.

    One suggested reading: http://www.ibm.com/developerworks/library/x-xmlphp3.html
     

Share This Page