![]() |
compare XML files, text vs numbers
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? |
What are you using to compare the two files? Maybe things would be a little eaier if you included the xml files your talking about.
Because "data in the format 0.5 " makes no sense to me and neither does "convert data to numbers/decimals" |
Quote:
<multiplyfactor>0.5</multiplyfactor> file2 <multiplyfactor>.5</multiplyfactor> When you compare these as text in xml they are different. |
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. |
Quote:
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? |
have you tried using a xml diff tool?
I use liquid studio and that has a fairly decent compare / diff tool. http://www.liquid-technologies.com/Compare-XML.aspx |
Quote:
Surely in code, you can check a schema t get a datatype? |
Quote:
Dave |
Quote:
ie everything has to have something before the decimal place? |
Quote:
Dave |
Quote:
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. |
It's easy enough, after parsing the xml, to insure that you have integers when you do math by forcing them to be numbers.
|
Quote:
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? |
Quote:
|
| All times are GMT +1. The time now is 01:08 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.