-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from ted-sc/better_xml
better_xml_handling
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,37 @@ public function serialize($payload) | |
return $dom->saveXml(); | ||
} | ||
|
||
/** | ||
* @param mixed $payload | ||
* @return string | ||
* @author Ted Zellers | ||
*/ | ||
public function serialize_clean($payload) | ||
{ | ||
$xml = new \XMLWriter; | ||
$xml->openMemory(); | ||
$xml->startDocument('1.0','ISO-8859-1'); | ||
$this->serialize_node($xml, $payload); | ||
return $xml->outputMemory(true); | ||
} | ||
|
||
/** | ||
* @param XMLWriter $xmlw | ||
* @param mixed $node to serialize | ||
* @author Ted Zellers | ||
*/ | ||
public function serialize_node(&$xmlw, $node){ | ||
if (!is_array($node)){ | ||
$xmlw->text($node); | ||
} else { | ||
foreach ($node as $k => $v){ | ||
$xmlw->startElement($k); | ||
$this->serialize_node($xmlw, $v); | ||
$xmlw->endElement(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @author Zack Douglas <[email protected]> | ||
*/ | ||
|