Can't extract double quoted text from XML?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Can't extract double quoted text from XML?

Post by BarrySumpter » Wed Aug 03, 2011 12:34 am

I have this data in lblFileContents:

Code: Select all

...
<period>Monthly</period>
<fee unit="AUD$">999.99</fee>
...


I call the function this way:

Code: Select all

put ExtractTagData("period") into strperiod   --works
put ExtractTagData("fee unit=" & quote & "AUD$" & quote,"Fee" ) into strFee  -- does NOT work


And the function works with anything but embedded double quotes:
(note:
The replace function finds the embedded double quotes without issue.
But for some reason the wordOffset function does NOT)

Code: Select all

Function ExtractTagData tagName, tagEndName
   
   put field lblFileContents into tagData
   
   if tagEndName is Empty then
      put tagName into tagEndName
   end if
   
   replace "<" & tagName & ">" with " <" & tagName & "> " in tagData      -- this replace finds the fee with double quotes
   replace "</" & tagEndName & ">" with " </" & tagEndName & "> " in tagData
   
   Put wordOffset("<" & tagName & ">",tagData) into tWordStartNum       -- this wordOffset DOES NOT find the fee with double quotes
   Put wordOffset("</" & tagEndName & ">",tagData) into tWordEndNum
   
   Delete word tWordEndNum to -1 of tagData
   Delete word 1 to tWordStartNum of tagData
   
   return tagData
   
end ExtractTagData
Any positive constructive suggestions would be greatly appreciated.
Last edited by BarrySumpter on Wed Aug 03, 2011 4:55 am, edited 2 times in total.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Can't extract double quoted text from XML?

Post by Dixie » Wed Aug 03, 2011 1:40 am

Assuming that

<period>Monthly</period>
<fee unit="AUD$">999.99</fee>

is in fld 1 for this example, then...

Code: Select all

on mouseUp
   put fld 1 into theTagData
   put theFee(theTagData)
end mouseUp

function theFee theDataToExtract
   delete line 1 of theDataToExtract
   put lineOffset("<fee unit=",theDataToExtract) into theLine
   replace "<fee unit=" with empty in line theLine of theDataToExtract
   repeat with count = the number of chars of  theDataToExtract down to 1
      if char count of theDataToExtract = quote then delete char count of theDataToExtract
   end repeat
   replace "</fee>" with empty in line theLine of theDataToExtract
   replace ">" with "=" in line theLine of theDataToExtract
   return theDataToExtract
end theFee
will return :- AUD$=999.99

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: Can't extract double quoted text from XML?

Post by BarrySumpter » Wed Aug 03, 2011 4:54 am

Dixie rules!

Thanks so much for the excellent post.
Doing stuff I've never seen.
Nice.

Man! Thats a lot of work.

I should have thought about the replace the unit with empty.
I think unit is called an attribute and the fee is called a tag.

Code: Select all

replace "fee unit=" & quote & "AUD$" & quote with "fee" in lblFileContents 
then

Code: Select all

put ExtractTagData("fee") into strFee   --works
Unless I actually NEED that currency type later. filter something. i'll experiment later.
But for now it's just for me.

----

Also I can never remember if "" is the same in livecode as null or empty or blank.
Its empty.
And I can never remember type casting.
The one that bugs me the most is
... the label of field label1
I always want to do
.. the lable of label label1
I'm not even sure I got that right. LOL.

I'll have to write a cheat sheet an leave in on me wall.
Unless someone already has a cheat sheet they use and don't mind sharing.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

Post Reply