php - Append DOMDocument root element to another DOMDocument -


I have 2 "DOMDocument" objects - $ Original and $ Excess I want to get all the children from an additional docdocument $ And add $ end to the end of the original document.

I had to take the original element of the $ extra document I tried to use: $ root = $ Extra-> Document element; $ Original- & gt; Append Child ($ root)

But I get an error, which is expected of Ependon Child as a logon object. I tried to access every child in the document via:

  $ extra-> childNodes-> Item (0);   

But it gives the purpose of domelimity Can you advise how to obtain an object of a domonode class? What is the most convenient way to provide this import operation?

The $ basic XML looks like this:

  & lt ;? Xml version = "1.0" encoding = "UTF-8" & gt; & Lt; Products & gt; & Lt; RecordReference & gt; 345,345 & lt; / RecordReference> & Lt; NotificationType & gt; 03 & lt; / NotificationType & gt; & Lt; Number of pages & gt; 100 & lt; / NumberOfPages & lt; / Products & gt;   

$ looks like the additional XML:

    

What do I have to do:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Products & gt; & Lt; RecordReference & gt; 345,345 & lt; / RecordReference> & Lt; NotificationType & gt; 03 & lt; / NotificationType & gt; & Lt; NumberOfPages & gt; 100 & lt; / NumberOfPages & gt; & Lt; MainSubject & gt; & Lt; SubjectScheme & gt; 10 & lt; / SubjectScheme & gt; & Lt; / MainSubject & gt; & Lt; / Products & gt;  

A DOMElement is a domonode, the domondode superclass is for element, text and other nodes. There are many child classes here just repeat, import and add them.

  $ targetDom = newdomdocument (); $ TargetDom- & gt; LoadXML ('& lt; root / & gt;'); $ SourceDom = new DOMDocument (); $ SourceDom- & gt; LoadXml (' gt; & lt; child / & gt; text & lt; / items & gt;'); Foreign currency ($ sourceDom-> document element-> child nodes $ child) {$ targetDom-> document element-> Append Chilled ($ target-> importer ($ child, TRUE);); }   

This also works with document element.

  $ targetDom = newdomdocument (); $ TargetDom- & gt; LoadXML ('& lt; root / & gt;'); $ SourceDom = new DOMDocument (); $ SourceDom- & gt; LoadXml (' gt; & lt; child / & gt; text & lt; / items & gt;'); $ TargetDom- & gt; Document Element- & gt; Append Child ($ targetDom-> Importation ($ sourceDom-> Document element, TRUE); Echo $ targetDom-> SaveXml ();   

DOMDocument :: importNode () creates a copy of the node given in the context of the document. Only nodes related to a document can be added.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -