Hello all,
I am working on DOM Functions and have a bit of problem. What I am trying to do is to ask my code to look in an XML file (say XML 1 document) to fetch some Xpath.Using this Xpath look in another XMLfile(say XML2 document) to fetch in the respective data and put this data in <Value> tag of XML1 document.
And All this works fine.
THE PROBLEM : If the XML1 document has already got some <value> tag with data in it, how do I replace it with the new data.
Following is my piece of code
$sXpath = $doc->getElementsByTagName("sxpath");
foreach($sXpath as $node) {
$xpath= $node->textContent;
Use the Xpath to get data from xml
$xpathQuery = $sp->query($xpath);
foreach ($xpathQuery as $node1) {
$dataFromS= $node1->textContent;
}
$refnode=$node;
$parentnode = $refnode->parentNode;
$newnode = $doc->createElement('value',$dataFromS );
$newnode = $parentnode->insertbefore($newnode, $refnode);
$dataFromS=''; //Reset The value
}
I tried adding the following piece of code which I thought would remove all the tags with name<value> but seems thats not the correct way out.
$value=$doc->getElementsByTagName("value");
foreach($value as $val){
if ($node->nodeName == 'value' && $node->hasAttributes()){
$oldnode = $doc->removeChild($val);}}
Thanks in advance
regards