[Tutor] Problems with creating XML-documents
Alan Gauld
alan.gauld at btinternet.com
Thu Apr 15 02:00:13 CEST 2010
"Karjer Jdfjdf" <karper12345 at yahoo.com> wrote
> I'm having problems with creating XML-documents,
> because I don't seem to write it to a document correctly.
Is that because you don't understand XML or because the
output is not what you expect? How is the data being generated?
Are you parsing an existing XML source or creating the XML
from scratch? I'm not sure I understand your problem.
> text = str('<record id="' + str(instance.id)+ '">\n' + \
' <date>' + str(instance.datetime) + ' </date>\n' + \
' <order>' + instance.order + ' </order>\n' + \
'</record>\n')
You can simplify this quite a lot. You almost certaionly don;t need
the outer str() and you probably don;t need the \ characters either.
Also it might be easier to use a triple quoted string and format
characters to insert the dasta values.
> When I try to parse it, it keeps giving errors.
Why do you need to parse it if you are creating it?
Or is this after you read it back later? I don't understand the
sequence of processing here.
> So I tried to use an external library jaxml,
Did you try to use the standard library tools that come with Python,
like elementTree or even sax?
I think we need a few more pointers to the root cause here.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list