Best way to map one XML onto another? No schema provided, just a sample.
-
I have two XML files,
source
anddestination
. Both have the same information (roughly) but in different formats. Mainly renaming elements and reorganization (one has a nested collection where the other just has siblings, etc). I need to take the information fromsource
and map it intodestination
's format for import/merging. Any ideas as to the easiest programmatic way of doing this? There are quite a few (160k+ lines @ between 20 and 100 lines each) entries, so manual modification is to be avoided if possible.
-
This is what XSLT was designed to do.
-
@dfdub said in Best way to map one XML onto another? No schema provided, just a sample.:
This is what XSLT was designed to do.
Which means I need to learn XSLT. Any good place to start? How do I actually trigger it? Because this is a one-time import/conversion.
-
@Benjamin-Hall
It's been a while since I last used it. The Wikipedia page has an examples section to get you started and also a list of XSLT processors. It might be as simple as referencing the style sheet in the source file and opening it in a browser of your choice.
-
And it worked! Only took a couple hours to figure out, but the imported file (once I actually got past all the transformation errors, which mostly were of the "unclosed tag" type) works well. I did have to wrestle with some idiotic design decisions made by the producer and consumer (different idiotic decisions). This "index" is 0-indexed. That "index" is 1-indexed. Had to spot check cases against the original to figure out what the index was to and where it started. But it worked.
-
@Benjamin-Hall this is why, despite all the hate it gets, I still like some things about xml. It's painful sometimes, but man does it have the tooling for anything.
-
@Magus I just wish XML Schema was more expressive. It's good enough for editor support, but usually not enough for actual validation.
-
@dfdub said in Best way to map one XML onto another? No schema provided, just a sample.:
but usually not enough for actual validation
It depends on how good you are at writing schemas (most tooling for making schemas doesn't use the full power of the XML Schema spec) and how many higher-level constraints you also have (such as “this attribute must match the name of an element over in that section”). There's also RELAX NG but there's a lot less tooling for that.