Skip to content

Commit

Permalink
Merge pull request #138 from ted-sc/better_xml
Browse files Browse the repository at this point in the history
better_xml_handling
  • Loading branch information
Nate Good committed Jul 17, 2014
2 parents e923b8e + aae86e8 commit 1ec25aa
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Httpful/Handlers/XmlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]>
*/
Expand Down

0 comments on commit 1ec25aa

Please sign in to comment.