/** * Resursive helper function for converting to XML * * @param QuickBooks_XML_Node $node * @param integer $tabs * @param boolean $empty A constant, one of: QUICKBOOKS_XML_XML_PRESERVE, QUICKBOOKS_XML_XML_DROP, QUICKBOOKS_XML_XML_COMPRESS * @param string $indent * @return string */ public function _asXMLHelper($node, $tabs, $empty, $indent) { $xml = ''; if ($node->childCount()) { $xml .= str_repeat($indent, $tabs) . '<' . $node->name(); foreach ($node->attributes() as $key => $value) { // Make sure double-encode is *off* //$xml .= ' ' . $key . '="' . QuickBooks_XML::encode($value, true, false) . '"'; $xml .= ' ' . $key . '="' . QuickBooks_XML::encode($value) . '"'; } $xml .= '>' . "\n"; foreach ($node->children() as $child) { $xml .= $this->_asXMLHelper($child, $tabs + 1, $empty, $indent); } $xml .= str_repeat($indent, $tabs) . '</' . $node->name() . '>' . "\n"; } else { if ($node->hasAttributes()) { $xml .= str_repeat($indent, $tabs) . '<' . $node->name(); foreach ($node->attributes() as $key => $value) { // Double-encode is *off* //$xml .= ' ' . $key . '="' . QuickBooks_XML::encode($value, true, false) . '"'; $xml .= ' ' . $key . '="' . QuickBooks_XML::encode($value) . '"'; } // Double-encode is *off* //$xml .= '>' . QuickBooks_XML::encode($node->data(), true, false) . '</' . $node->name() . '>' . "\n"; $xml .= '>' . QuickBooks_XML::encode($node->data()) . '</' . $node->name() . '>' . "\n"; } else { if ($node->hasData() or $empty == QUICKBOOKS_XML_XML_PRESERVE) { // Double-encode is *off* //$xml .= str_repeat($indent, $tabs) . '<' . $node->name() . '>' . QuickBooks_XML::encode($node->data(), true, false) . '</' . $node->name() . '>' . "\n"; $xml .= str_repeat($indent, $tabs) . '<' . $node->name() . '>' . QuickBooks_XML::encode($node->data()) . '</' . $node->name() . '>' . "\n"; } else { if ($empty == QUICKBOOKS_XML_XML_COMPRESS) { $xml .= str_repeat($indent, $tabs) . '<' . $node->name() . ' />' . "\n"; } else { if ($empty == QUICKBOOKS_XML_XML_DROP) { // do nothing, drop the empty element } } } } /* $xml .= str_repeat($indent, $tabs) . '<' . $node->name(); foreach ($node->attributes() as $key => $value) { $xml .= ' ' . $key . '="' . htmlentities($value, ENT_QUOTES) . '"'; } if ($node->data()) { $xml .= '>' . htmlentities($node->data()) . '</' . $node->name() . '>' . "\n"; } else if ($compress) { $xml .= ' />' . "\n"; } else { $xml .= '></' . $node->name() . '>' . "\n"; } */ } return $xml; }