Skip to content

Commit

Permalink
Fix merge method logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Edujugon committed Apr 12, 2018
1 parent 7a7c118 commit b03f32a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Also updates the underlying object based on the new xml.

#### Merge a new xml into the existing one

You can easily merge a new xml into the existing one just after a provided tag name.
You can easily merge a new xml into the existing one. It sets it as child of the provided tag.

```php
$mapper->mergeXML($newXml, 'desiredParentTag');
Expand Down
6 changes: 2 additions & 4 deletions src/XMLMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,8 @@ public function findAllAttributesOfWhere($tag, $where, $obj = null)
*/
public function mergeXML($xml, $intoTag)
{
$toMerge = new static($xml);
// Set tag name to "merged"
$toMerge->replaceTagName(['xml' => 'merged']);
$xml = $toMerge->getXml();
// remove xml tag declaration if any
$xml = preg_replace('/<\?xml.*?>/', '', $xml);

$endTag = '</' . $intoTag . '>';
$long = strlen($endTag);
Expand Down
2 changes: 1 addition & 1 deletion tests/XMLMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function replate_tag_name()
public function merge_xmls()
{
$first = $this->loadXML();
$second = '<xml id="33"><content att="something"><first><second><extras><extra name="f" id="2" company="acne"></extra><extra name="edujugon" id="1" company="acne"></extra></extras></second></first></content></xml>';
$second = '<?xml id="33"?><content att="something"><first><second><extras><extra name="f" id="2" company="acne"></extra><extra name="edujugon" id="1" company="acne"></extra></extras></second></first></content>';

$this->mapper->loadXML($first);

Expand Down

0 comments on commit b03f32a

Please sign in to comment.