bug with & in xml settings

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
Jon100
Non-Subscriber
Posts: 32
Joined: Wed Nov 24, 2004 1:38 pm

bug with & in xml settings

Post by Jon100 » Fri May 30, 2008 9:38 am

I think there is a bug in how IS/LS handles settings that contain an Ampersand (&) symbol.

Code: Select all

function main()
{
	declare myString string script "${SettingXML[myXMLfile.xml].Set[mySet].GetString[myString].Escape}"
	echo "${myString}"
}

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>
<!-- Generated by LavishSettings v2 -->
<InnerSpaceSettings>
	<Set Name="mySet">
		<Setting Name="myString">dog + bone.</Setting>
	</Set>
</InnerSpaceSettings>
Output = dog + bone.
(As expected)

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>
<!-- Generated by LavishSettings v2 -->
<InnerSpaceSettings>
	<Set Name="mySet">
		<Setting Name="myString">dog & bone.</Setting>
	</Set>
</InnerSpaceSettings>
Output=NULL
What is worse is it makes all other settings in hte file unreadable too. Is this a general problem with xml or a bug specific to IS/LS?
Jon100 / Dorset
"No of course I don't use that macro thingy to 6 box... I just use 6 keyboards at once..."

Lax
Owner
Posts: 6634
Joined: Fri Jun 18, 2004 6:08 pm

Post by Lax » Fri May 30, 2008 9:58 am

As part of the XML specification, the ampersand has special meaning:

http://www.w3.org/TR/REC-xml/#syntax
The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings "&amp;" and "&lt;" respectively. The right angle bracket (>) may be represented using the string "&gt;", and MUST, for compatibility, be escaped using either "&gt;" or a character reference when it appears in the string "]]>" in content, when that string is not marking the end of a CDATA section.
If you use an ampersand character like that, the XML is no longer valid, and this is why it fails to load and the other settings unreadable. This will usually only happen when writing the XML manually. If you, for example, use LavishSettings (note: you should switch to that instead of SettingXML which is deprecated) to set a setting to contain "dog & bone" it will transform it into the valid XML for you, like so:

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>
<!-- Generated by LavishSettings v2 -->
<InnerSpaceSettings>
   <Set Name="mySet">
      <Setting Name="myString">[color=red]dog &amp; bone.[/color]</Setting>
   </Set>
</InnerSpaceSettings>
So.. any time you are editing an XML file manually, make sure your edits follow the proper XML syntax, or programs don't have to try to read it if they don't want to. The quote I pasted is probably the only thing you need worry about, so you don't need to go through the whole XML specification if you don't want to ;)

Jon100
Non-Subscriber
Posts: 32
Joined: Wed Nov 24, 2004 1:38 pm

Post by Jon100 » Fri May 30, 2008 11:12 am

Ok :) Thanks Lax.
Jon100 / Dorset
"No of course I don't use that macro thingy to 6 box... I just use 6 keyboards at once..."

Post Reply