newbie qns : how do i use xmldiff?

S

sWrath swrath

Hi ,

I am pretty new to python , and reading up on it.

Basically I am trying to compare xml files . I know difflib have it
but it does not work out as expected. I was looking at xmldiff ,
unfortunately I am not able to find documentation how to call it from
python. Anyone knows a link or doc to it as I have been looking high
and low for few days?

lastly , is there a py (or algorithm) where it behaves exactly like
diff ? Greatly appreciated.

Thanks
john
 
T

Terry Reedy

Hi ,

I am pretty new to python , and reading up on it.

Basically I am trying to compare xml files . I know difflib have it
but it does not work out as expected. I was looking at xmldiff ,
unfortunately I am not able to find documentation how to call it from
python. Anyone knows a link or doc to it as I have been looking high
and low for few days?

When asking such a question, it is good to explain what sort of thing,
in this case, 'xmldiff' is and where it is is from. Let us assume you
meant xmldiff from

http://www.logilab.org/859

It says it is a python tool that can "be used be used as a library or as
a command line tool." It includes a README file. Have you read that?
That says "USAGE ... Read the HELP.txt file.". Have you read *that*?
HELP.txt seems to focus on command line usage. I would start with that.
To use it as a library (via import ...), you might have to look at the
source code as I did not see importing covered in my quick look at that
file.

Terry Jan Reedy
 
N

No Name

I had to do some fishing around to figure this much out. Hope it helps.

from input import * # From the xmldiff directory
from fmes import * # From the xmldiff directory
from format import * # From the xmldiff directory
from StringIO import *

# Build your original tree
text1 = '<point><x>1</x><y>2</y><z>3</z></point>'
stream1 = StringIO(text)
tree1 = tree_from_stream(stream)

# Build your modified tree
text2 = '<point><x>2</x><y>2</y><z>3</z></point>'
stream2 = StringIO(text2)
tree2 = tree_from_stream(stream2)

# Compare the trees
formatter = InternalPrinter()
corrector = FmesCorrector(formatter)
corrector.process_trees(tree, tree2)

## OUTPUT:
## Instructions for modifying original to modified
# [rename, /point[1]/y[1], x]
# [insert-after, /point[1]/x[2],
# <y>
# 2
# </y>
# ]
# [remove, /point[1]/x[1]]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top