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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:06:49+00:00 2026-05-23T05:06:49+00:00

Is it possible to use the php://temp wrapper to generate an XML file with

  • 0

Is it possible to use the php://temp wrapper to generate an XML file with XMLWriter? I like the features it provides (memory for small files, transparent temporary file for larger output) but I can’t get the syntax (if it’s even possible):

<?php

header('Content-type: text/xml; charset=UTF-8');

$oXMLWriter = new XMLWriter;
$oXMLWriter->openURI('php://temp');
$oXMLWriter->startDocument('1.0', 'UTF-8');

$oXMLWriter->startElement('test');
$oXMLWriter->text('Hello, World!');
$oXMLWriter->endElement();

$oXMLWriter->endDocument();
// And now? *******
$oXMLWriter->flush();
  • 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-23T05:06:49+00:00Added an answer on May 23, 2026 at 5:06 am

    I don’t understand the purpose of writing to a temp file. Perhaps you want:

    $oXMLWriter->openURI('php://output');
    

    I haven’t ever used XMLWriter but it doesn’t seem to take a handle to a file pointer. I think that’s really what you want.

    For giggles, here’s something that wraps the temp interface:

    class WeirdStream
    {
      static public $files = array();
      private $fp;
    
      public function stream_open($path)
      {
        $url = parse_url($path);
        self::$files[$url['host']] = fopen('php://temp', 'rw');
        $this->fp = &self::$files[$url['host']];
        return true;
      }
    
      public function stream_write($data)
      {
        return fwrite($this->fp, $data);
      }
    }
    
    stream_wrapper_register('weird', 'WeirdStream');
    
    $oXMLWriter = new XMLWriter;
    $oXMLWriter->openURI('weird://a');
    // .. do stuff
    $oXMLWriter->flush();
    

    Now you can get at the file pointer:

    $fp = WeirdStream::$files['a'];
    

    It may be purely in memory, or it may be a temporary file on disk.

    You could then loop through the data line by line:

    fseek($fp, 0, SEEK_SET);
    while (!feof($fp)) $line = fgets($fp);
    

    But this is all very odd to me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use PHP's SimpleXML functions to create an XML object from
Is it possible to restrict direct access to PHP file if I use jquery
Question: Is it possible to use php://memory on a exec or passthru command? I
I would like to ask if it's possible to use PHP in removing a
I was wondering if it's possible to use php to create a file with
Is it possible to use a regular expression with the php function array_key_exists() ?
Possible Duplicate: Why should I use templating system in PHP? I was just curious
Is it possible to use php's preg_replace to remove anything in a string except
Is it possible to use PHP magic methods (specifically __get()) outside a defined class?
Possible Duplicate: Why use a framework with PHP? To begin with, I just can

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.