Solved

XML CreateElement

Posted on 2014-11-07
2
141 Views
Last Modified: 2014-11-10
Hi,

I have an existing script that outputs an XML file, I need to alter the header and add some elements, I need some pointers please, examples below:

This is the header code:
$dom = new DOMDocument('1.0', 'utf-8');
 $element = $dom->createElement('DTD_ORDER');

This outputs:
<?xml version="1.0" encoding="utf-8"?>
<DTD_ORDER>*******************</DTD_ORDER>

What I need to do is add in some elements so result looks like:

<SyncSalesOrder xmlns:v2="http://xmlns.oracle.com/EnterpriseObjects/Core/Common/V2" xmlns:v1="http://xmlns.oracle.com/EnterpriseObjects/Core/EBO/PickList/V1" releaseID="9.0" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns="http://www.openapplications.org/oagis/9"><ApplicationArea><Sender><LogicalID>5029125000000</LogicalID><ComponentID></ComponentID><TaskID>SalesOrder</TaskID><ReferenceID>1</ReferenceID></Sender><CreationDateTime>2014-11-04T18:53:51+10:30</CreationDateTime></ApplicationArea><DataArea><Sync><ActionCriteria><ActionExpression actionCode="Sync"/></ActionCriteria></Sync><DTD_ORDER>*************</DTD_ORDER></DataArea></SyncSalesOrder>


Where
The ReferenceId should be the transmission number(date/hour as 0711201408)
The CreationDateTime should be the transmission date and time

Getting bogged down in this, any help appreciated

Thanks
0
Comment
Question by:tonypearce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40431493
This should work for you:
$dom = new DOMDocument('1.0', 'utf-8');

    $SyncSalesOrder = $dom->createElementNS('http://www.openapplications.org/oagis/9', 'SyncSalesOrder');
        $SyncSalesOrder->setAttribute('releaseID', '9.0');
        $SyncSalesOrder->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:v2', 'http://xmlns.oracle.com/EnterpriseObjects/Core/Common/V2');
        $SyncSalesOrder->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:v1', 'http://xmlns.oracle.com/EnterpriseObjects/Core/EBO/PickList/V1' );
        $SyncSalesOrder->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:wsa', 'http://www.w3.org/2005/08/addressing');

        $ApplicationArea = $dom->createElement('ApplicationArea');
            $Sender = $dom->createElement('Sender');
                $LogicalID = $dom->createElement('LogicalID', '5029125000000');
                $Sender->appendChild($LogicalID);

                $ComponentID = $dom->createElement('ComponentID');
                $Sender->appendChild($ComponentID);

                $TaskID = $dom->createElement('TaskID', 'SalesOrder');
                $Sender->appendChild($TaskID);

                $ReferenceID = $dom->createElement('ReferenceID', date('mdYH')); // The ReferenceId should be the transmission number(date/hour as 0711201408)
                $Sender->appendChild($ReferenceID);
            $ApplicationArea->appendChild($Sender);

            $CreationDateTime = $dom->createElement('CreationDateTime', date('c')); // The CreationDateTime should be the transmission date and time
            $ApplicationArea->appendChild($CreationDateTime);
        $SyncSalesOrder->appendChild($ApplicationArea);

        $DataArea = $dom->createElement('DataArea');
            $Sync = $dom->createElement('Sync');
                $ActionCriteria = $dom->createElement('ActionCriteria');
                    $ActionExpression = $dom->createElement('ActionExpression');
                        $ActionExpression->setAttribute('actionCode', 'Sync');
                    $ActionCriteria->appendChild($ActionExpression);
                $Sync->appendChild($ActionCriteria);
            $DataArea->appendChild($Sync);

            $element = $dom->createElement('DTD_ORDER', '*************');
            $DataArea->appendChild($element);
        $SyncSalesOrder->appendChild($DataArea);
    $dom->appendChild($SyncSalesOrder);

Open in new window

manual pages I used:
http://php.net/manual/en/function.date.php
http://php.net/manual/en/domdocument.createelementns.php
http://php.net/manual/en/domelement.setattributens.php
0
 

Author Comment

by:tonypearce
ID: 40432163
Hi,
Thanks very much, learnt a lot by seeing the code in place, php.net is good, but sometimes needs 'real world' examples, very good solution.
Tony
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question