User Name
Password
AppleNova Forums » Programmer's Nook »

XML Plumbing


Register Members List Calendar Search FAQ Posting Guidelines
XML Plumbing
Thread Tools
Banana
is the next Chiquita
 
Join Date: Feb 2005
 
2008-11-08, 00:17

I have two objects from two libraries that are incompatible with each other. It happens that both supports writing and reading to/from XML, so I figured I would use XML as the bridge between two objects I need to access.

However, after examining the output of XML generated, it is apparent that they do not use same format, and will refuse to read XML generated by other library. Both XMLs pass the well-formedness test, but fails validation (the validator complains that it couldn't find the root element xml... ). I figured that some people may had same problems and had to automate diff between XMLs. A quick google return me only one useful product and they want dough for it.

So I'm coming on here, in hopes that some soul here has same problem and may be able to point me toward a good way to automate the diff and thus translate between two XML into format that is acceptable for both objects.

(Though at this point, I question whether this is actually easier to do than just to manually write the codes necessary to interface between the two objects...)
  quote
Kickaha
Likes his boobies blue.
 
Join Date: May 2004
Location: Hell
 
2008-11-08, 00:23

General diffing of XML files from two different schemas is easy:

They're different.

XML is a container format, not a data format. It's like saying "I can't play this QuickTime movie!" without knowing what the underlying codec is.

In the general case, even with the same schema being used in the two files, a diff becomes a graph isomorphism problem, which scale badly and are a pain to get right.

Write the mapper, knowing what you do about the two metamodels being used for the data. It'll be easier.

@kickaha@social.seattle.wa.us
#IRC isn't old school... Old school is being able to say 'finger me' with a straight face.
  quote
Banana
is the next Chiquita
 
Join Date: Feb 2005
 
2008-11-08, 00:31

One library does provide the functionality to write out the schema without the data, but I don't think that's the case with another library, which makes it one way, I think. Will review the documentation to be 100% sure, but that's a good idea- writing out the schema and and re-write it into the expected format for the other library.
  quote
Kickaha
Likes his boobies blue.
 
Join Date: May 2004
Location: Hell
 
2008-11-08, 11:08

Consider using an XSLT, in that case - it's what it's for. It will read the one format and emit the other.
  quote
Banana
is the next Chiquita
 
Join Date: Feb 2005
 
2008-11-08, 11:50

Perfect, looks like what I need for the job.

Many thanks!
  quote
Enki
Senior Member
 
Join Date: Nov 2004
 
2008-11-08, 12:37

Quote:
Originally Posted by Kickaha View Post
General diffing of XML files from two different schemas is easy:

They're different.

XML is a container format, not a data format. It's like saying "I can't play this QuickTime movie!" without knowing what the underlying codec is.

In the general case, even with the same schema being used in the two files, a diff becomes a graph isomorphism problem, which scale badly and are a pain to get right.

Write the mapper, knowing what you do about the two metamodels being used for the data. It'll be easier.
And just one mans simplification: XML is a language for writing other data storage languages, so just because something used XML doesn't mean it is compatible with something else's XML out of he box.

XML does have lots of nice tools though, and more all the time, which allow users to address the compatibility issues with a minimum of extra work. XSLT is a good example in this case, without the XML you would need to write a binary translation engine from scratch---Yuck!
  quote
Kickaha
Likes his boobies blue.
 
Join Date: May 2004
Location: Hell
 
2008-11-08, 13:19

Quote:
Originally Posted by Enki View Post
And just one mans simplification: XML is a language for writing other data storage languages, so just because something used XML doesn't mean it is compatible with something else's XML out of he box.
That's a better and more precise way of describing it, thanks. The QT container/codec issue was the first that popped to mind as a common analogy.

Quote:
XML does have lots of nice tools though, and more all the time, which allow users to address the compatibility issues with a minimum of extra work. XSLT is a good example in this case, without the XML you would need to write a binary translation engine from scratch---Yuck!
Hear, hear. I use a custom XML schema for all of my research data. When I first decided on it five years ago, I was told I was nuts - it was too cumbersome, too verbose, the files were too big, it was too slow to work with...

But now I have a suite of XSLTs that can transform the one file format into visualizations (UML, using GraphViz and the dot format), compute fairly complex metrics, and even formats for consumption by other tools in industry and academia.

Are they lightning fast? Not always. I had to do some serious work to get one of them down to practical speeds. (Initially the transformation for one 20MB file took over 9 hrs on my MBP... I got it down to under 5 min with some algorithmic changes.)

But useful? Flexible? Hell yeah.

Banana, one warning: XSLT is a functional programming language first and foremost, not procedural. It is a little... different. Trying to make it act like a procedural language is *possible*, but it's not simple or recommended. It's better to go with the flow and get into the functional mindset, rather than try and beat it to match procedural experience.

@kickaha@social.seattle.wa.us
#IRC isn't old school... Old school is being able to say 'finger me' with a straight face.

Last edited by Kickaha : 2008-11-08 at 13:30.
  quote
Banana
is the next Chiquita
 
Join Date: Feb 2005
 
2008-11-08, 14:00

Warning noted. Will do some reading up on what is expected in a functional language- Oodles of fun ahead!
  quote
Posting Rules Navigation
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Post Reply

Forum Jump
Thread Tools

« Previous Thread | Next Thread »

All times are GMT -5. The time now is 05:19.


Powered by vBulletin®
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2023, AppleNova