Solved

XML CreateElement

Posted on 2014-11-07
2
142 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 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