How can I strip the first line from DOMDocument->saveXML()

Discussion in 'PHP' started by krt, Jun 18, 2007.

  1. #1
    I am coding a lightweight controller that outputs XML. I'm currently trialling the DOMDocument object and using its saveXML() method. Only problem is that I want the XML inserted as a segment in the main XML file. But, the saveXML() includes <?xml version="1.0"?> on the first line and I don't want it.

    I also don't want to do something like:
    $doc = new DOMDocument('1.0');
    // add stuff to $dom, possibly resulting in a very large document
    
    $xml = $doc->saveXML();
    $xml = substr($xml, strpos($xml, "\n"));
    // or...
    substr($doc->saveXML(), strpos($doc->saveXML(), "\n"));
    
    PHP:
    Anyone got any ideas to do this? Preferably without requiring extra server load...

    Thanks in advance :)
     
    krt, Jun 18, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    
    $doc = new DOMDocument("1.0");
    $xml = $doc->saveXML( );
    $xml = substr( $xml, strpos( $xml, "\n") );
    
    PHP:
    That works and is less server load the saving the xml twice
     
    krakjoe, Jun 18, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Yes, I don't know why I included the alternative :p
    But I'm trying to figure out a way to do this without doing either of those, not that I seem to have much choice.
     
    krt, Jun 18, 2007 IP