开发者

Import of XML nodes and removing namespace

I have a XML feed of products that I break down into smaller XML files using DOMDocument and DOMXpath in PHP.

I create the new XML file, add a root node then import all the deep-copied nodes from the main feed. I want to remove the namespace from the imported node.

I have tried $node->removeAttributeNS( 'myurl' , '' ) which correctly removes the xmlns attribute from the node but creates a default namespace so the output looks like

<default:node />

would like to remove any trace of namespaces associated with the imported node ready for r开发者_StackOverflow社区egistering new namespaces.

Any tips gratefully received.


I'm not sure if this is actually what you are looking for but have you thought about using xml_parser_create() or `xml_parser_create_ns() to create a parser and then set your own processing functions to remove the namespaces.

$xmlParser = xml_parser_create();
xml_set_element_handler($xmlParser, "startElementHandler", "endElementHandler"); // start and end ElementHandlers are call backs to your handling functions that handle the beginning and ending of tags.
xml_set_default_handler($xmlParser, "handleMe"); // handleMe is a callback to your function to handle the data inside the tags.
xml_parse($xmlParser, $xmlData);

There are more functions that can be used to handle the xml found at php.net

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜