Convert a string into XML

Hi,

I’m trying to write a script that converts a string into XML (with built in XML suite in Tiger). I can find a lot of examples on how to read from an XML file, but none (so far) on how to create your own from a string. I managed to get the job done with XML Tools and even XMLlib but I want to use the built in XML suite because it makes the script (easy) useable on other mac’s. This is an example string:

1Some text

I’ve tried something like:

set TheXML to "<verse><nr>1</nr><tekst>Some text</tekst></verse>"
tell application "System Events"
	set the_elements to every XML element of TheXML
end tell

But that gives me an error.
Any thoughts on how this might be done?

Model: G5 dual 1.8
Browser: Safari 417.8
Operating System: Mac OS X (10.4)

I’m confused. In the example you posted it appears that you are attempting to convert XML to text. You state however, that you are trying to convert text to XML. The string in your example is already marked up with XML tags. Please be more specific on what you are trying to do. If your XML is not that complex you could create it just using plain Applescript to manipulate and build your XML (no additions needed).

CarbonQuark

Let me try to explain. I use a Music notation program that specifies the lyrics your working with (e.g. this is verse 1, this is verse 2, this is chorus 1). I’m trying to create a script that takes a string, divides it into different lyrics-parts and puts the lyrics-parts in the right ‘box’. I need a way to put the lyrics-part into different variables (Verse_1, Verse_2, etc.). So I created a script that puts XML-like tags around the different lyrics-parts (as found in the example string). Now I need a way to ‘read’ the XML and do something like:


set Verse_1 to item 1 of (every XML element of TheXML)

AppleScript, however, doesn’t consider the string XML. I’m not very into XML (I’m a little bit into AppleScript, but also not a very intelligent scripter) but I know that I have to parse the string as XML before XML suite can use it as XML.

So my question is: how do I convert a string to XML with the built in XML suite.

Thanks in advance for your thoughts (and sorry for the indistinctness in my first post).

Bart

Operating System: Mac OS X (10.4)