Problem with simpleXML and addChild

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stockholm
Forum Newbie
Posts: 3
Joined: Wed Dec 03, 2008 7:46 am

Problem with simpleXML and addChild

Post by stockholm »

Hi!

First at all, it seems like you got really big forums here, so I hope i'll get an answer.
I'm just developing a class to access a service, which is providing a credit card check XML API.

First I got this XML base:

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1" ?>  <acdc:Root xmlns:acdc="urn:acdc_gateway">  </acdc:Root>
I use the following Code:

Code: Select all

$sxe = new SimpleXMLElement($this->xml_header);
$test = $sxe->addChild('testchild', '010101');
$test->addAttribute('testattr', '12345');
But, if I use this code, I got this:

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1"?>
<acdc:Root xmlns:acdc="urn:acdc_gateway">
 <acdc:testchild testattr="12345">010101</acdc:testchild>
</acdc:Root>
Instead of:

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1"?>
<acdc:Root xmlns:acdc="urn:acdc_gateway">
 <testchild testattr="12345">010101</testchild>
</acdc:Root>

So it's addinc "acdc:" to every child.

Ideas, Suggestions?

Thanks!
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Problem with simpleXML and addChild

Post by panic! »

looks like it's adding a namespace

http://uk2.php.net/manual/en/function.s ... spaces.php


I have no idea how to remove a namespace....
Post Reply