PHP / XML - replace chunk of XML in middle of file -
okay, i'm bit stumped. i'm more familiar python when manipulating xml, use php in instance if possible.
is there relatively straightforward way replace chunk of text - children , values given node - in xml file set of elements?
starting this:
<rdf:rdf xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:fedora="info:fedora/fedora-system:def/relations-external#" xmlns:myns="http://www.nsdl.org/ontologies/relationships#"> <rdf:description rdf:about="info:fedora/cfai:eb01a004"> <fedora:ismemberofcollection rdf:resource="info:fedora/cfai:collection"/> </rdf:description> </rdf:rdf>
and looks this:
<rdf:rdf xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:fedora="info:fedora/fedora-system:def/relations-external#" xmlns:myns="http://www.nsdl.org/ontologies/relationships#"> <rdf:description rdf:about="info:fedora/cfai:eb01a004"> <element>these new elements paste in.</element> <element>this another, string of elements</element> </rdf:description> </rdf:rdf>
i've got loaded simple_xml_loadfile, i've got namespaces cooking registerxpathnamespace, i'm having embarassingly hard time figuring out how 1) remove nodes, , 2) insert own chunk of text in place.
any appreciated.
you use unset() remove node:
unset($xml->node);
and add element:
$node = $xml->addchild('node'); $node->addchild('title', 'i'm node'); $node->addchild('title2', 'another node');
Comments
Post a Comment