Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 983627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:53:18+00:00 2026-05-16T04:53:18+00:00

I would like to add a child, on a very specific place (so I’m

  • 0

I would like to add a child, on a very specific place (so I’m also using DOM and not only simpleXML) for <domain:create> node.

I have tried to use the $ns attribute on simpleXML construct.

$nsNode = new SimpleXMLElement('<domain:ns>', $options = 0, $ns='urn:ietf:params:xml:ns:domain-1.0');

//transform the target into dom object for manipulation
$nodeRegistrantDom = dom_import_simplexml($nodeRegistrant);

But I’m getting:

I/O warning : failed to load external
entity "<domain:ns>"

I’ve tried to register the prefix after creating the element,
but I use no xpath after this, so this was quite a useless try…

//creates the simpleXML object node to be inserted.
$nsNode = new SimpleXMLElement('<ns/>');

//this will not work, because we will not use xpath after it :s
$nsNode->registerXPathNamespace('domain', 'urn:ietf:params:xml:ns:domain-1.0');

Since the xml is loaded from a file, and that file as this ns declared, maybe we should grab it from that file?

Here is an overall of the above, so that we can better understand the context:
We are loading a XML file that contains an overall structure:

 $xmlObj = simplexml_load_file('EppCreateDomain.xml');

They we will grab an element that we will use as a target:

//grab the target.
    $nodeRegistrant = $xmlObj->command->create->children(self::OBJ_URI_DOMAIN)->create->registrant;

    //transform the target into a dom object for later manipulation
    $nodeRegistrantDom = dom_import_simplexml($nodeRegistrant);

//we try to use simpleXML to create the node that we want to add after our target.
    $nsNode = new SimpleXMLElement('<domain:ns>');


//grabs the node and all his children (none in this case), by importing the node we want to add,
//into the root object element that contains the <domain:registrant> node.
$nsNodeDom = $nodeRegistrantDom->ownerDocument->importNode(dom_import_simplexml($nsNode), true);

$nodeRegistrantDom->parentNode->insertBefore($nsNodeDom, $nodeRegistrantDom->nextSibling);

$simpleXmlNsNode = simplexml_import_dom($nsNodeDom);

Now we have our node placed on a proper place.
And converted to simpleXML so, we can now easily add some children and fill the rest of the xml file..

$hostAttr = $simpleXmlNsNode->addChild('domain:hostAttr');
$hostName = $hostAttr->addChild('domain:hostName');

Please advice,
MEM

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:53:19+00:00Added an answer on May 16, 2026 at 4:53 am
    <?php
    // test document, registrant as first/last element and somewhere in between
    $xmlObj = new SimpleXMLElement('<epp>
      <domain:create xmlns:domain="urn:someurn">
        <domain:name></domain:name>
        <domain:registrant></domain:registrant>
        <domain:contact></domain:contact>
      </domain:create>
      <domain:create xmlns:domain="urn:someurn">
        <domain:name></domain:name>
        <domain:contact></domain:contact>
        <domain:registrant></domain:registrant>
      </domain:create>
      <domain:create xmlns:domain="urn:someurn">
        <domain:registrant></domain:registrant>
        <domain:name></domain:name>
        <domain:contact></domain:contact>
      </domain:create>
    </epp>');
    
    foreach( $xmlObj->children("urn:someurn")->create as $create ) {
      $registrant = $create->registrant;
      insertAfter($registrant, 'domain:ns', 'some text');
    }
    echo $xmlObj->asXML();
    
    function insertAfter(SimpleXMLElement $prevSibling, $qname, $val) {
      $sd = dom_import_simplexml($prevSibling);
      $newNode = $sd->ownerDocument->createElement($qname, $val);
      $newNode = $sd->parentNode->insertBefore($newNode, $sd->nextSibling);
      return simplexml_import_dom($newNode);
    }
    

    prints

    <?xml version="1.0"?>
    <epp>
      <domain:create xmlns:domain="urn:someurn">
        <domain:name/>
        <domain:registrant/><domain:ns>some text</domain:ns>
        <domain:contact/>
      </domain:create>
      <domain:create xmlns:domain="urn:someurn">
        <domain:name/>
        <domain:contact/>
        <domain:registrant/><domain:ns>some text</domain:ns>
      </domain:create>
      <domain:create xmlns:domain="urn:someurn">
        <domain:registrant/><domain:ns>some text</domain:ns>
        <domain:name/>
        <domain:contact/>
      </domain:create>
    </epp>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add a css class to a child view from a
I would like to add a hash into an array using Ruby version 1.8.7:
I would like to add a collection of objects to an arrayList ,only if
I would like to add a child component while inside of the encodeBegin public
I have own project and i would like add for this class same as
I have a ListView and each item have a TextView. I would like add
I would like to add a GestureDetector to all views (view groups) of an
I would like to add a custom calculation method to a managed object (which
I would like to add roots to a VirtualTreeView http://www.delphi-gems.com/index.php/controls/virtual-treeview with a thread like
I would like to add up the number of line changes in an SVN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.