You are here

function XMLTag::GetXML in Asset 6

Same name in this branch
  1. 6 asset_youtube/xmlparser.class.php \XMLTag::GetXML()
  2. 6 asset_youtube/inc/xmlparser.class.php \XMLTag::GetXML()
Same name and namespace in other branches
  1. 5 asset_youtube/xmlparser.class.php \XMLTag::GetXML()

Returns the string of the XML document which would be generated from this object

This function works recursively, so it gets the XML of itself and all of its children, which in turn gets the XML of all their children, which in turn gets the XML of all thier children, and so on. So, if you call GetXML from the document root object, it will return a string for the XML of the entire document.

This function does not, however, return a DTD or an XML version/encoding tag. That should be handled by XMLParser::GetXML()

Return value

string

File

asset_youtube/xmlparser.class.php, line 324

Class

XMLTag
XML Tag Object (php4)

Code

function GetXML() {

  //Start a new line, indent by the number indicated in $this->parents, add a <, and add the name of the tag
  $out = "\n" . str_repeat("\t", $this->tagParents) . '<' . $this->tagName;

  //For each attribute, add attr="value"
  foreach ($this->tagAttrs as $attr => $value) {
    $out .= ' ' . $attr . '="' . $value . '"';
  }

  //If there are no children and it contains no data, end it off with a />
  if (empty($this->tagChildren) && empty($this->tagData)) {
    $out .= " />";
  }
  else {

    //If there are children
    if (!empty($this->tagChildren)) {

      //Close off the start tag
      $out .= '>';

      //For each child, call the GetXML function (this will ensure that all children are added recursively)
      foreach ($this->tagChildren as $child) {
        $out .= $child
          ->GetXML();
      }

      //Add the newline and indentation to go along with the close tag
      $out .= "\n" . str_repeat("\t", $this->tagParents);
    }
    elseif (!empty($this->tagData)) {
      $out .= '>' . $this->tagData;
    }

    //Add the end tag
    $out .= '</' . $this->tagName . '>';
  }

  //Return the final output
  return $out;
}