SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: XML Parsing

  1. #1
    SitePoint Addict scoobasteve1982's Avatar
    Join Date
    Apr 2007
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML Parsing

    Hi there,

    Just a quick question here...when parsing an XML document I have some empty nodes. When I pull through an XML parser (like DOMDocument), any empty nodes are stripped to a single tag. Below is an example of what is happening:

    Code:
    ...
    <PREF NAME="name"></PREF>
    ...
    gets modified to

    Code:
    ...
    <PREF NAME="name"/>
    ...
    I understand that this is still acceptable XML formation, however I do NOT want PHP to do this. Is there anyway to turn this off so it doesn't mess with my data.

    Thanks!

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    You can use the libxml constant LIBXML_NOEMPTYTAG always expand empty tags into an opening and closing pair.

    PHP Code:
    $sXml '
    <TEST>
        <PREF NAME="name"></PREF>
    </TEST>
    '
    ;

    $oDom = new DOMDocument;
    $oDom->loadXML($sXml);
    echo 
    $oDom->saveXML($oDomLIBXML_NOEMPTYTAG); 
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Addict scoobasteve1982's Avatar
    Join Date
    Apr 2007
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Salathe!


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
  •