AFAIK, when comparing data in 2 xml files, everything is passed as text or characters.
This means that data in the format 0.5 in one file will appear different to data in the second file reading .5 as the precision is different.
Is there a way to convert data to numbers/decimals first in XML and compare?
qwertyjjj, XML has no concept of numbers, believe it or not. A parsed DOM of your document will look like this:
multiplyfactor (element)
-- .5 (text node, whose value is a string)
Your best bet would be to have some custom scripting to identify elements containing numbers, and then convert their contents to actual numbers using parseInt or whatever your language's equivalent is.
__________________
"The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
June 30, 2001
author, Verbosio prototype XML Editor
author, JavaScript Developer's Dictionary https://alexvincent.us/blog
qwertyjjj, XML has no concept of numbers, believe it or not. A parsed DOM of your document will look like this:
multiplyfactor (element)
-- .5 (text node, whose value is a string)
Your best bet would be to have some custom scripting to identify elements containing numbers, and then convert their contents to actual numbers using parseInt or whatever your language's equivalent is.
What is the best way to do this?
Give each XML item an attribute with the datatype or the schema should contain the element datatype and then the software can check the schema?
Surely in code, you can check a schema t get a datatype?
I don't know how that's going to help, though. Both your examples (0.5 and .5) would be valid against the same schema, so what would that tell you? I agree, the way to do this seems to be to load the two xml files into a program and "walk" the objects comparing them.
I don't know how that's going to help, though. Both your examples (0.5 and .5) would be valid against the same schema, so what would that tell you? I agree, the way to do this seems to be to load the two xml files into a program and "walk" the objects comparing them.
Dave
couldn't the schema have precision and scale?
ie everything has to have something before the decimal place?
couldn't the schema have precision and scale?
ie everything has to have something before the decimal place?
Unfortunately I'm no master of the schema, but logically I'm going to guess that this is not a "schema issue" as both those numbers are completely legitimate representations of "one half". You may need to write a little test example and see if there's a way to get a schema validation to fail one and accept the other.
Unfortunately I'm no master of the schema, but logically I'm going to guess that this is not a "schema issue" as both those numbers are completely legitimate representations of "one half". You may need to write a little test example and see if there's a way to get a schema validation to fail one and accept the other.
Dave
I guess the problem is how to tell the software to check them as a number rather than a string so that it doens;t find a difference when it compares the,
If it knows it's a decimal, then it sees 0.5 the same as .5, which is correct.
Let's step back a bit. First and foremost: what is going to consume the XML? Specifically, what programming or scripting language is that consumer written in?
This is most important, since XML without something to parse it is just a string of characters. The language will place constraints and expose capabilities that XML itself doesn't have.
__________________
"The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
June 30, 2001
author, Verbosio prototype XML Editor
author, JavaScript Developer's Dictionary https://alexvincent.us/blog
Ok, but imagine that xml file has 100 different elements.
How does the parser know which is meant to be a decimal, which a string, which a date, etc.
You either hardcode it in the software or you check the schema?
Pretty much.
__________________
"The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
June 30, 2001
author, Verbosio prototype XML Editor
author, JavaScript Developer's Dictionary https://alexvincent.us/blog