473,320 Members | 1,841 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,320 software developers and data experts.

XMLObject - problem with recursive definitions

I've been using the excellent XMLObject and have unfortunately come up
against what *looks* to me like a bug - although it's very possible
that the problem is mine !!

I want to use XML object to create an XML structure that represents
the contents of a directory structure. I call it a DirObj. Each DirObj
needs a list node that can itself contaibn several more DirObj -
effectively a 'recursive' definition.

It looks something like this :

class XMLDirObj(XMLObject):
"""An XMLObject version of a DirObj."""
attrs = ItemNode('DirAttributes')
files = ListNode('XMLFileObj')
dirs = ListNode('XMLDirObj')

A DirAttributes object is an object representing the set of attributes
of the directory, an XMLFileObj is an object representing the set of
attributes of each file in the directory. Unfortunately when I use the
toXml and then the (classmethod) fromXml it mangles the values. (on
the read).

I've written a small test script with the simplest possible recursive
use of XMLObject and it doesn't appear to work. I wondered if this was
actually a bug - or whether I was doing something wrong. My test
script is below and from the sample output you'll see the error and
the assert failure at the bottom. The first print is ok (toXml) - but
then it reads it incorrectly (the second print).

Ouput :

<?xml version="1.0" encoding="iso-8859-1" ?>
<thing abit="Hello My Friend">
<thing abit="Recursion Test">
<anotherthing abit="Yo Again"/>
</thing>
<anotherthing abit="Yo"/>
</thing>
<?xml version="1.0" encoding="iso-8859-1" ?>
<thing abit="Hello My Friend">
<thing abit="Recursion Test">
<anotherthing abit="Yo Again"/>
</thing>
<anotherthing abit="Yo Again"/>
</thing>
Traceback (most recent call last):
File "D:\Python Projects\dirwatcher\rec_test.py", line 67, in ?
assert thestuff == thestuff2
AssertionError
####################
"""
rec_test.py

Demonstrates that recursion fails using XMLObject

:-(

"""
from XMLObject import *
################################################## ######################
class Thing(XMLObject):
place = ItemNode('Anotherthing')
anotherplace = ListNode('Thing')
abit = CDATAttribute(optional=True)

class Anotherthing(XMLObject):
abit = CDATAttribute(optional=True)
################################################## ######################
# Test Function

if __name__=='__main__':
test1 = Thing()
test1.abit = 'Hello My Friend'
athing = Anotherthing()
athing.abit = 'Yo'
test1.place = athing

test2 = Thing()
test2.abit = 'Recursion Test'
athing2 = Anotherthing()
athing2.abit = 'Yo Again'
test2.place = athing2

test1.anotherplace.append(test2)

thestuff = test1.toXml()
print thestuff

testobj = Thing.fromXml(thestuff)
thestuff2 = testobj.toXml()

print
print
print thestuff2

assert thestuff == thestuff2
#####################################

If anyone can see what I've done wrong it would be much appreciated.
(I've emailed the author - but as it's probably my fault I thought I'd
post here as well).
Regards,

Fuzzy


--

http://www.Voidspace.org.uk
The Place where headspace meets cyberspace. Online resource site -
covering science, technology, computing, cyberpunk, psychology,
spirituality, fiction and more.

---
http://www.Voidspace.org.uk/atlantib...thonutils.html
Python utilities, modules and apps.
Including Nanagram, Dirwatcher and more.
---
http://www.fuchsiashockz.co.uk
http://groups.yahoo.com/group/void-shockz
---

Everyone has talent. What is rare is the courage to follow talent
to the dark place where it leads. -Erica Jong
Ambition is a poor excuse for not having sense enough to be lazy.
-Milan Kundera
Jul 18 '05 #1
3 1654
fu******@gmail.com (Michael Foord) wrote in
news:6f**************************@posting.google.c om:
I've been using the excellent XMLObject and have unfortunately
come up against what *looks* to me like a bug - although it's
very possible that the problem is mine !!

[...]

I copied your code, installed XMLObject (thanks for mentioning
this, by the way -- I had not been aware of it before), and ran the
program, which worked fine.

Output:
<?xml version="1.0" encoding="iso-8859-1" ?>
<thing abit="Hello My Friend">
<thing abit="Recursion Test">
<anotherthing abit="Yo Again"/>
</thing>
<anotherthing abit="Yo"/>
</thing>
<?xml version="1.0" encoding="iso-8859-1" ?>
<thing abit="Hello My Friend">
<thing abit="Recursion Test">
<anotherthing abit="Yo Again"/>
</thing>
<anotherthing abit="Yo"/>
</thing>
.... but this was based on the latest XMLObject. Maybe it's been
patched in response to your message?

--
rzed

Jul 18 '05 #2
Apparently this has already been fixed - and a new release will be
made in the next couple of days with this fixed....

I'm just surprised it wasn't my fault :-)

Fuzzy

fu******@gmail.com (Michael Foord) wrote in message news:<6f**************************@posting.google. com>...
I've been using the excellent XMLObject and have unfortunately come up
against what *looks* to me like a bug - although it's very possible
that the problem is mine !!

I want to use XML object to create an XML structure that represents
the contents of a directory structure. I call it a DirObj. Each DirObj
needs a list node that can itself contaibn several more DirObj -
effectively a 'recursive' definition.

It looks something like this :

class XMLDirObj(XMLObject):
"""An XMLObject version of a DirObj."""
attrs = ItemNode('DirAttributes')
files = ListNode('XMLFileObj')
dirs = ListNode('XMLDirObj')

A DirAttributes object is an object representing the set of attributes
of the directory, an XMLFileObj is an object representing the set of
attributes of each file in the directory. Unfortunately when I use the
toXml and then the (classmethod) fromXml it mangles the values. (on
the read).

I've written a small test script with the simplest possible recursive
use of XMLObject and it doesn't appear to work. I wondered if this was
actually a bug - or whether I was doing something wrong. My test
script is below and from the sample output you'll see the error and
the assert failure at the bottom. The first print is ok (toXml) - but
then it reads it incorrectly (the second print).

Ouput :

<?xml version="1.0" encoding="iso-8859-1" ?>
<thing abit="Hello My Friend">
<thing abit="Recursion Test">
<anotherthing abit="Yo Again"/>
</thing>
<anotherthing abit="Yo"/>
</thing>
<?xml version="1.0" encoding="iso-8859-1" ?>
<thing abit="Hello My Friend">
<thing abit="Recursion Test">
<anotherthing abit="Yo Again"/>
</thing>
<anotherthing abit="Yo Again"/>
</thing>
Traceback (most recent call last):
File "D:\Python Projects\dirwatcher\rec_test.py", line 67, in ?
assert thestuff == thestuff2
AssertionError
####################
"""
rec_test.py

Demonstrates that recursion fails using XMLObject

:-(

"""
from XMLObject import *
################################################## ######################
class Thing(XMLObject):
place = ItemNode('Anotherthing')
anotherplace = ListNode('Thing')
abit = CDATAttribute(optional=True)

class Anotherthing(XMLObject):
abit = CDATAttribute(optional=True)
################################################## ######################
# Test Function

if __name__=='__main__':
test1 = Thing()
test1.abit = 'Hello My Friend'
athing = Anotherthing()
athing.abit = 'Yo'
test1.place = athing

test2 = Thing()
test2.abit = 'Recursion Test'
athing2 = Anotherthing()
athing2.abit = 'Yo Again'
test2.place = athing2

test1.anotherplace.append(test2)

thestuff = test1.toXml()
print thestuff

testobj = Thing.fromXml(thestuff)
thestuff2 = testobj.toXml()

print
print
print thestuff2

assert thestuff == thestuff2
#####################################

If anyone can see what I've done wrong it would be much appreciated.
(I've emailed the author - but as it's probably my fault I thought I'd
post here as well).
Regards,

Fuzzy


--

http://www.Voidspace.org.uk
The Place where headspace meets cyberspace. Online resource site -
covering science, technology, computing, cyberpunk, psychology,
spirituality, fiction and more.

---
http://www.Voidspace.org.uk/atlantib...thonutils.html
Python utilities, modules and apps.
Including Nanagram, Dirwatcher and more.
---
http://www.fuchsiashockz.co.uk
http://groups.yahoo.com/group/void-shockz
---

Everyone has talent. What is rare is the courage to follow talent
to the dark place where it leads. -Erica Jong
Ambition is a poor excuse for not having sense enough to be lazy.
-Milan Kundera

Jul 18 '05 #3
rzed <je***@comics.com> wrote in message
[snip..]
<?xml version="1.0" encoding="iso-8859-1" ?>
<thing abit="Hello My Friend">
<thing abit="Recursion Test">
<anotherthing abit="Yo Again"/>
</thing>
<anotherthing abit="Yo"/>
</thing>
... but this was based on the latest XMLObject. Maybe it's been
patched in response to your message?


Yeah - the new release 0.1.2 corrects the problem.
It's the first XML library I've used. I'm using it for both reading
and writing data structures as XML rather than a general XML
parser...... but it's very easy to use.

Regards,
Fuzzy

http://www.voidspace.org.uk/atlantib...thonutils.html
Jul 18 '05 #4

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

Similar topics

0
by: srijit | last post by:
Hello, There are two different XMLObject Projects 1) http://xmlobject.sourceforge.net/ 2) http://xmlobject.base-art.net/ This is confusing. Regards, Srijit
7
by: Mac | last post by:
Under certain circumstances isinstance() seems to return incorrect value for me. I'm using Python 2.3 (latest from Debian's unstable). Here's a sample program... the multi-module nature of the...
20
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"...
4
by: Konstantin Shemyak | last post by:
I have a big structure tree. All leaves are scalar values (no pointers). Present are arrays, structures and unions. I want to be able to store/read the content of the structure in/from a file, and...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
6
by: jeniffer | last post by:
Please give an example of 2 simple mutually recursive functions in C .
29
by: Ancient_Hacker | last post by:
It sure would be nice if I could have a macro that add a level of indirection to its argument. So if I write: AddIndirection( X ) The macro AddIndirection will do: #define X (*X) ...
14
by: pamela fluente | last post by:
I want to use the ordinary OpenFileDialog to choose a folder instead of a file. Is it possible? And how? -P
9
by: JFS | last post by:
I know most of you have probably read "The C Programming Language" (K&R) at some point. Well here is something that is driving me crazy. The exercises are impossible (most of them) for me to do....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.