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 657537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:50:07+00:00 2026-05-13T22:50:07+00:00

<?php include ../music/php/logic/core.php; include ../music/php/logic/settings.php; include ../music/php/logic/music.php; $top = At world’s end; // create

  • 0
<?php

include "../music/php/logic/core.php";
include "../music/php/logic/settings.php";
include "../music/php/logic/music.php";
$top = "At world's end";


// create doctype
$dom = new DOMDocument("1.0");

header("Content-Type: text/xml");

?>

<music>
<?php $_xml = "<title>".$top."</title>";
echo $_xml; ?>
</music>

I’m using this code to generate a dynamic XML document. The file is saved as PHP.
My problem is that I can’t echo php variables into the xml. However I can echo “literal” type text. I can’t see anything wrong with my approach, it just doesn’t work!

I’m pretty new to XML so I’ve probably missed something glaringly simple.

I’ve also tried lines like:

<title><?php echo $top; ?></title>
  • 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-13T22:50:07+00:00Added an answer on May 13, 2026 at 10:50 pm

    You don’t use DOM this way. You use the DOM API to create the entire document:

    $doc   = new DOMDocument();
    $books = $doc->createElement( "books" );
    $doc->appendChild( $books );
    // ...
    

    See:

    • http://www.ibm.com/developerworks/library/os-xmldomphp/
    • http://www.tonymarston.net/php-mysql/dom.html
    • https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-6141415.html

    A more verbose example (generating XHTML with DOM)

    // Create head element
    $head = $document->createElement('head');
    $metahttp = $document->createElement('meta');
    $metahttp->setAttribute('http-equiv', 'Content-Type');
    $metahttp->setAttribute('content', 'text/html; charset=utf-8');
    $head->appendChild($metahttp);
    

    See this tutorial on how to use DOM for XHTML. For reuse of code, you can write your own classes extending DOM classes to get configurable components.


    If you don’t want to use DOM or want to use plain text for generating the XML, just approach it like any other template, e.g.

    <root>
        <albums>
            <album id="<?php echo $albumId; ?>">
                <title><?php echo $title; ?></title>
                ... other elements ...
            </album>
        </albums>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is example which I have try <?php include 'spider/classes/simple_html_dom.php'; $html = new simple_html_dom();
<?php include(stdio.h); function main() { printf(Hello World); return 0; } ?> Error on line
I am using MCrypt.php index.php include(MCrypt.php); $crypter = new MCrypt(); MCrypt.php exists in same
How would one go about using php include() with GET paramters on the end
My sample index.php include 'class.php'; $x = new class; include $_GET['page'].'.php'; //checks if isset
When i use php include to include a page in my website all the
This is user.php: include(databse.php);//retrieving successfully first name and lastname from databse file into user.php
In my live site I have php include() and require() that have full path
I have a php file that looks like this: <?php include(config.php); // put the
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();

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.