473,385 Members | 1,824 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.

Xml writing in Python and verifying using XSD

Hi,

I need to write some data to an xml file. I have an XML Schema defined.
I would like to use some mechanism of writing the data to the xml file
and having exceptions thrown back to me when the data is invalid.

I have looked at xml.dom and xml.dom.minidom but could not figure out
what to do to include xml validation using the xsd while writing.

Any ideas?

Thanks in advance,
Prashanth Ellina

Jul 19 '05 #1
2 4848
Prashanth Ellina wrote:
Hi,

I need to write some data to an xml file. I have an XML Schema defined.
I would like to use some mechanism of writing the data to the xml file
and having exceptions thrown back to me when the data is invalid.

I have looked at xml.dom and xml.dom.minidom but could not figure out
what to do to include xml validation using the xsd while writing.

Any ideas?


Use StringIO to capture the output of your writings, and use a
xsd-validating parser (not sure which one, but google should help) to
reread that. Or a temporary file.

Apart from that I don't see much chances - which has nothing to do with
python but with xml itself: xml isn't suited for streams, because of the
opening/closing tags - and noone can forsee if an opened tag in the stream
is closed in the future. Only after you finished the writing of that
document itself you can do that.

Similar arguments apply to DOMs. A DTD/XSD might require a certain element
to have a childelement. But when creating the element it has no childs - so
the document would be invalid. In the end you can only validate a finished
dom tree. So the only thing that could be tried is to feed that dom tree
instead of a xml string to a validation process - but if that's doable I'm
not sure, and it doesn't buy you too much performance gain. So stick with
the write/validate process described above.

--
Regards,

Diez B. Roggisch
Jul 19 '05 #2


Diez B. Roggisch wrote:
Use StringIO to capture the output of your writings, and use a
xsd-validating parser (not sure which one, but google should help) to
reread that. Or a temporary file.


Thank you very much. I'll try that.

Jul 19 '05 #3

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

Similar topics

4
by: HD | last post by:
Hi, I was wondering if there is a way of verifying information that is in the registry of the user's computer??? Or is there a way of checking if a file is on the c:\ of the user's computer?? I...
9
by: Carter Smith | last post by:
http://www.icarusindie.com/wiki/index.php/Server-Side_Javascript_Check Sample source included This method requires that your pages are PHP enabled and you have mySQL. Although I suppose you...
159
by: petantik | last post by:
Are there any commercial, or otherwise obfuscators for python source code or byte code and what are their relative advantages or disadvantages. I wonder because there are some byte code protection...
11
by: Michael Spencer | last post by:
Announcing: compiler2 --------------------- For all you bytecode enthusiasts: 'compiler2' is an alternative to the standard library 'compiler' package, with several advantages. Improved...
5
by: Payala | last post by:
Hello, I have tried to install python 2.5.1 and 2.5.2 with the same error. The installer starts fine, but when it gets to the part that says "Status: Copying new files" it terminates with an error...
16
by: rahul | last post by:
void foo(void) { /* blah blah */ } char buf = {....}; memcpy( (void *)&foo, buf, sizeof buf); This thing is giving segmentation fault on RHEL 5/gcc 4.1. Is the text segment protected? I am...
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
1
by: Ryan Freckleton | last post by:
Hi Everyone, I'm currently developing a decorator and metaclass based implementation of design by contract for python. (I'd have uploaded it to PyPI already, but I haven't had time to create a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.