Solved

XML CreateElement

Posted on 2014-11-07
2
135 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
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now