Page 1 of 1

XML Processing

Posted: Mon Aug 05, 2013 2:57 am
by Nakia
Hi,

I am working with XML at the moment (I hate XML by the way) and I have hit an issue with trying to parse out a value that has a period in it...

The XML Data looks like this (example)
<?xml version="1.0" encoding="UTF-8"?>
<day-entries type="array">
<day-entry>
<adjustment-record type="boolean">false</adjustment-record>
<created-at type="datetime">2013-07-01T23:14:16Z</created-at>
<hours type="decimal">0.3</hours>

The value I am trying to parse out is the "hours" tag.
I am using the below code to parse but only get returned the "0." not the "0.3"

Any ideas as to why it only returns the data before the period?

put revXMLNodeContents(tXMLEntries, "day-entries/day-entry/hours") after tCurrentProjectNameList

Re: XML Processing

Posted: Tue Aug 06, 2013 1:06 am
by Nakia
Anyone got some idea's???

I can get any of the other tags sucessfully that dont have a period in the value...

Re: XML Processing

Posted: Tue Aug 06, 2013 2:04 am
by Simon
Replace?
Sure it's a workaround :(

Simon

Re: XML Processing

Posted: Tue Aug 06, 2013 4:12 am
by Nakia
I suppose I could try that...Maybe something like replacing the period with a comma, need to keep something there to
determine actual correct number (0.3 as apposed to 30.03)

repeat with x = the number of lines of tXMLVar down to 1
if "hours" is among the text of line x of tXMLVar then
replace "." with comma
end if
end repeat

Re: XML Processing

Posted: Tue Aug 06, 2013 5:22 am
by Simon

Code: Select all

replace "." with comma in line x of tXMLVar 
Haven't tried it myself, but I think that's better. You might even think about one of those unprintable characters to replace it with. People seem fond of using them.

Too bad its a workaround. I hope someone around here knows better, seems to be something common, having a decimal point.

I got a question Kia, do you think it would have been better for me not to have replied to your posting? It could be that sometimes if a post has an answer (right or wrong) people who know the correct answer might not bother looking at it?

Simon

Re: XML Processing

Posted: Tue Aug 06, 2013 7:01 am
by Nakia
Thanks Simon,

Its funny you ask that question as in my opinion LiveCode is all about not having the correct answer but providing a solution.
I often reply back to posts with a work around and in my opinion that is the power and prupose of a Forum.

If someone is looking for only answers, use stackOverflow

Re: XML Processing

Posted: Tue Aug 06, 2013 7:22 am
by Simon
If someone is looking for only answers, use stackOverflow
Nice!

I was wondering what a difference could be.

Simon

Re: XML Processing

Posted: Wed Aug 07, 2013 5:38 am
by Nakia
Turns out there was a weird error in my code that caused this...
Very long story to fully explain but my code was actually modifying the data before parsing out the result