Create XML via PHP - Help needed urgently

Hi friends,

I have been trying various functions of DOMDocument. I have managed to create a simple XML, but I need to create an XML in the following format. I think I would be able to use the relevant variables for replacing values. Can someone help me create this as a static XML?

<BookedSeatCountMsg xsi:schemaLocation=" BookedSeatCount.xsd" xmlns="" xmlns:xsi="">
      <BookedSeatCount classOfService="J">
                  <PsgrInfo passengerType="M">
      <BookedSeatCount classOfService="M">
                        <PsgrInfo passengerType="A">
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Beverley PortlockCommented:
You say that the XML is to be static. In that case mark the values you wish to replace with some easily spotted text and use str_replace to swap them for the actual values. The code fragment below illustrated the sort of thing I'm talking about although I have only done part of it.

Also, see for more info. To Dynamically generate XML then PHP's SimpleXML would probably do the job.


$xml = '<BookedSeatCountMsg xsi:schemaLocation=" BookedSeatCount.xsd" xmlns="" xmlns:xsi="">

  .... etc etc

// Get PHP variables
$airline = ....
$flightNum = .....

$newXml = str_replace( array("AIRLINE", "FLIGHT_NUM", "DEP_DATE", "ORIGIN", ....etc etc ),
                       array($airline,  $flightNum,   $depDate,   $origin ),


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.