Interacting with a complex XML file

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Interacting with a complex XML file

Post by kaveh1000 » Mon Oct 12, 2020 1:19 pm

Hi folks

Been a while since I have been on the forum but still here!!

I deal with quite complex and "rich" source XML files that are the contents of book chapters. My knowledge of XML and particularly the XML in question is very limited (but I have colleagues who can help if needed).

I need to enter some simple content (a few words) within the XML files, but not to interfere with the current content and tags. To use in LiveCode, I prefer to have simple HTML, so that I can use HTMLText, and use all the nifty text manipulation and highlighting features that I have. It is not hard to go from the XML to HTML, but the problem is going back to the original XML and putting back the complex tags.

Alternatively I can view the content using some special CSS files in a browser window, but then I cannot interact with the browser widget.

Sorry if I am bing a bit vague, but any ideas welcome. Happy to give more details.
Kaveh

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9833
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Interacting with a complex XML file

Post by FourthWorld » Mon Oct 12, 2020 3:39 pm

Have you explored the commands and functions in the revXML external? They're listed in the Dictionary, and are pretty comprehensive, quite good for most needs.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Interacting with a complex XML file

Post by kaveh1000 » Sun Oct 18, 2020 8:47 am

Hi Richard

Thanks for this pointer. Reason for my silence is I need to do a lot of homework now, probably using revXML. :-)

Kaveh
Kaveh

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Interacting with a complex XML file

Post by kaveh1000 » Tue Oct 27, 2020 4:56 pm

As usual, a one liner from Richard pointed me in the right direction at least to start. I can now examine XML files for structure, content, tree etc. I know that I can write to the XML file too using revXML.

Here's a bit more detail about what I want to do. I am certain it can be done with LiveCode and I bet there is an elegant solution somewhere. I deal with complex scientific publications. See e.g. this page as a random example:

https://journals.plos.org/plosone/artic ... ne.0236938

The XML of the article that you can see in HTML and in PDF, can be downloaded using the download button. I have also attached it here.

The use case is as follows. Suppose you want to read a scientific paper and then make comments on it, in situ. This can be done using web based annotation software (e.g. https://web.hypothes.is/). In our case, for very specific reasons we want to put those comments directly into the XML. So the reader might want to put the following:

Code: Select all

<comment>are you sure?</comment>
into this text:

Code: Select all

<p>
Future research should focus on ... frequency band [
<xref ref-type="bibr" rid="pone.0236938.ref047">47</xref>
]. PAM studies ... of Hainan Island.
</p>
resulting in:

Code: Select all

<p>
Future research should focus<comment>are you sure?</comment> on ... frequency band [
<xref ref-type="bibr" rid="pone.0236938.ref047">47</xref>
]. PAM studies ... of Hainan Island.
</p>
You can see that there is a lot of complex code that I don't want to modify. I just want to craftily insert the comment code.

Now I want the user interaction to be in a LiveCode field, with all the interaction facilities that LiveCode allows. The user will not need to see a perfect representation of the XML. A "baby" HTML version will do, e.g. using HTMLText.

So my idea is to create a two-way mapping of the original XML and the HTMLText in LiveCode, so that when user selects some text and presses a "comment" button, the comment is written into the XML, without disturbing the surrounding code. The main reason I want to use LiveCode is that I need very flexible and powerful interaction with the text. Conversion from XML to a readable LiveCode field text is not hard, but mapping between the two is challenging. Somehow each chunk of text in LiveCode needs to know exactly where it came from in the XML.

I am looking with the revXML commands, but I have also come across the following: Any pearls of wisdom appreciated and I am happy to give any more details.

Kaveh
Attachments
plos_example.xml.zip
(29.25 KiB) Downloaded 170 times
Kaveh

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”