Skip to content

Commit

Permalink
Merge pull request #20 from XueSiLf/2.x
Browse files Browse the repository at this point in the history
fix: Fixed the compatibility issue of DOMDocument::createCDATASection…
  • Loading branch information
XueSiLf authored Jul 9, 2024
2 parents bc90f12 + 0aa5e8c commit 6ca7321
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SplArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function toXML($CD_DATA = false, $rootName = 'xml', $subArrayItemKey = 'i
public function addCData($cdata_text)
{
$dom = dom_import_simplexml($this);
$cdata = $dom->ownerDocument->createCDATASection($cdata_text);
$cdata = $dom->ownerDocument->createCDATASection((string)$cdata_text);
$dom->appendChild($cdata);
}
};
Expand Down
25 changes: 25 additions & 0 deletions test/ArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,31 @@ public function testToXML(SplArray $splArrayObj) {
);
}

/**
* 转化成xml
*/
public function testToXML2()
{
$data = [
'fruit' => [
'apple' => 2,
'orange' => 1,
'grape' => 4,
'foo' => null,
],
'color' => [
'red' => 12,
'blue' => 8,
'green' => 6
]
];
$splArrayObj = new SplArray($data);
$this->assertEquals(
"<xml><fruit><apple><![CDATA[2]]></apple><orange><![CDATA[1]]></orange><grape><![CDATA[4]]></grape><foo><![CDATA[]]></foo></fruit><color><red><![CDATA[12]]></red><blue><![CDATA[8]]></blue><green><![CDATA[6]]></green></color></xml>\n",
$splArrayObj->toXML(true)
);
}

public function testMulti()
{
$splArray = new SplArray(
Expand Down

0 comments on commit 6ca7321

Please sign in to comment.