?
Solved

XML CreateElement

Posted on 2014-11-07
2
Medium Priority
?
143 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

777 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