473,385 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Output XML buffer?

Hello all,

I'm using ElementTree to create an XHTML page (mod_python, blah,
blah, blah). When I use ElementTree.tostring(root) to create a buffer
which I want to return to the client, it doesn't include the XML prolog
(obvisouly, since tostring is merely traversing the tree from the node I
supply to it.

I could simply prefix the tostring output with a string containing my
"<?xml ...>" schtick. But let's, for the sake of argument, say that I
trust a library more to generate it for me, rather than hand coding it
myself (not entirely true, but let's assume that is the case).

--
Kind regards,
Jan Danielsson
Jun 25 '07 #1
3 2153
I'm using ElementTree to create an XHTML page (mod_python, blah,
blah, blah). When I use ElementTree.tostring(root) to create a buffer
which I want to return to the client, it doesn't include the XML prolog
(obvisouly, since tostring is merely traversing the tree from the node I
supply to it.
Not at all obvious. It considered writing an XML prolog, but then
decided against it because the output encoding was UTF-8 or ASCII,
in which case the prolog can be safely omitted by the XML
recommendation.
I could simply prefix the tostring output with a string containing my
"<?xml ...>" schtick. But let's, for the sake of argument, say that I
trust a library more to generate it for me, rather than hand coding it
myself (not entirely true, but let's assume that is the case).
Did you mean to include some question? If you meant to ask "Can I make
it write an XML prolog, and if so, how?", then the anwser is:
use an output encoding different from utf-8 or us-ascii.

Regards,
Martin
Jun 25 '07 #2
Jan Danielsson wrote:
I'm using ElementTree to create an XHTML page (mod_python, blah,
blah, blah). When I use ElementTree.tostring(root) to create a buffer
which I want to return to the client, it doesn't include the XML prolog
As Martin told you, this is spec-compliant behaviour. Still, ElementTree 1.3
is expected to add a keyword argument "xml_declaration" in tostring() that
will let you override the default behaviour. lxml.etree already implements
that, BTW.

http://codespeak.net/lxml

I could simply prefix the tostring output with a string containing my
"<?xml ...>" schtick. But let's, for the sake of argument, say that I
trust a library more to generate it for me, rather than hand coding it
myself (not entirely true, but let's assume that is the case).
Some people propose just that if you really *want* a declaration. No need to
have it, though, as ET will create well-formed XML anyway.

Stefan
Jun 26 '07 #3
Stefan Behnel wrote:
[---]
lxml.etree already implements that, BTW.

http://codespeak.net/lxml
Ok, thanks. I'll take a look at it.

[---]
Some people propose just that if you really *want* a declaration. No need to
have it, though, as ET will create well-formed XML anyway.
Yeah, I checked the specs, and found a '?' there (but not where I
expected it to be). I just checked the first mention of the "header",
and didn't see it marked as optional.

However, I want it to be there, simply because it feels better. I'll
check lxml out.

--
Kind regards,
Jan Danielsson
Jun 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: vishal | last post by:
hi vishal here. can anyone tell me that how to buffer output and then send the output to client at a time. what is my problem is that i have a php file which runs query on database and takes...
9
by: Jay Donnell | last post by:
I have a function that is a few thousand lines of code (I didn't write it) and I want to capture the output and save it as a variable. This is very easy to do in php. It would look something like...
12
by: Matt Garman | last post by:
I'd like to create a "custom output facility". In other words, I want an object whose use is similar to std::cout/std::cerr, but offers more flexibility. Instead of simply writing the parameter...
9
by: Fred Ma | last post by:
Hello, I posted previously under the thread: How to break this up into streambuf/ostream I've asked our library to get "C++ IOStreams and Locales..." by A. Langer et al. Meantime, I've...
4
by: rossum | last post by:
I have been looking at exceptions as I need to get better at using them. I came across an interesting effect, demonstrated below. When I ctrl-Z the input to throw an ios_base::failure, the...
6
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
3
by: Blankdraw | last post by:
I'm getting NO errors and 2 warnings with this code. I thought I was ready to write the output-formatting segment, but may be way off the mark now. The warnings say that "OPEN() and READ() are...
8
by: walter.preuninger | last post by:
I am writing a program, using the gmp library. I need to take the output (mpz_out_str) and put it back into a string. Is there an easy way to take stream output, and 'place it' into a string? I...
2
by: Thormod Johansen | last post by:
Hi, I am doing some embedded programming in Paradigm C++, and I would like to be able to output debugging information using the << operator and ostreams. I have a serial link for which I have...
1
by: prads | last post by:
Hello, the foll pgm displays some wierd looking characters at the output when cout<<buffer<< is done. Pls tell me why it happens and also correct the error. Thanks, Prads int main () { ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.