Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6103709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:45:34+00:00 2026-05-23T13:45:34+00:00

$xml = new DOMDocument(); $xml_store_inventory = $xml->createElement(‘store-inventory’); // highest layer $xml_item = $xml->createElement(‘item’); $xml_quantity

  • 0
$xml = new DOMDocument();
$xml_store_inventory = $xml->createElement('store-inventory');  // highest layer
$xml_item = $xml->createElement('item');
$xml_quantity = $xml->createElement('quantity');

$xml->appendChild($xml_store_inventory);
$xml_store_inventory->appendChild($xml_item);
$xml_location->appendChild($xml_quantity);

gives:

<?xml version="1.0"?>
<store-inventory>
  <item>
      <quantity></quantity>
  </item>
</store-inventory>

So, I managed to create the above in PHP using DOM. I’ve been searching online on how to “populate,” but I’m not finding any information on how to do this.

More specifically, I’d like this to look like this

<?xml version="1.0" encoding="UTF-8"?>
<store-inventory
xmlns="http://..."
xmlns:xsi="http://..."
xsi:schemaLocation="http://...">

    <item item-id="abcd">
       <quantity>0</quantity>
    </item>
</store-inventory>

So, I’d like to add/change the following:

  1. change the XML version line to include encoding (scrape this, I figured out –> $xml = new DOMDocument(‘1.0’, ‘UTF-8’);)
  2. Add additional information to an element. e.g. [item] to [item item-id=”abcd”]
  3. Also [quantity] to [quantity]0[/quantity]

Can someone help me with this? TIA!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:45:35+00:00Added an answer on May 23, 2026 at 1:45 pm

    You’re already pretty close.

    2: set an attribute:

    // set/add an attribute:
    $xml_item->setAttribute('item-id', "abcd");
    

    3: add data while adding a tag/element:

    // add an element with data:
    $xml_quantity = $xml->createElement('quantity', '0');
    

    2+: Use HTMLSpecialchars to prevent the browser to hide the tags:

    echo nl2br(html_specialchars($xml->saveXML(), ENT_QUOTES));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create XML record. I started with this: $doc = new DomDocument('1.0',
Here's the XML code I'm working with: <inventory> <drink> <lemonade supplier=mother id=1> <price>$2.50</price> <amount>20</amount>
I was wondering how i should go about writing an XML data layer for
I am trying to parse the following XML file in Java and to store
I'm generating an XML document in VBA using the MSXML2.DOMDocument and then sending the
I've an old big application in php that uses XML (DOMDocument). The application works
The XML <?xml version=1.0?> <items version=1.5> <item name=device>iphone</item> <item name=affinity>testing</item> </items> I need to
I have generated a XML file automatically from the below code. if (isset($_POST[song])&& $_POST['song']
I'm trying to fully validate an xml file which may be published by a
I'm trying to get a C++ service to load an XML document from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.