XML Processing

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

XML Processing

Post by Nakia » Mon Aug 05, 2013 2:57 am

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

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: XML Processing

Post by Nakia » Tue Aug 06, 2013 1:06 am

Anyone got some idea's???

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: XML Processing

Post by Simon » Tue Aug 06, 2013 2:04 am

Replace?
Sure it's a workaround :(

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: XML Processing

Post by Nakia » Tue Aug 06, 2013 4:12 am

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: XML Processing

Post by Simon » Tue Aug 06, 2013 5:22 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: XML Processing

Post by Nakia » Tue Aug 06, 2013 7:01 am

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: XML Processing

Post by Simon » Tue Aug 06, 2013 7:22 am

If someone is looking for only answers, use stackOverflow
Nice!

I was wondering what a difference could be.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: XML Processing

Post by Nakia » Wed Aug 07, 2013 5:38 am

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

Post Reply