XML Parsing error checklist for krpano.

Posted by | April 11, 2012 | krpano | No Comments

When you get an error such as this one:

ERROR: XML parsing failed - ReferenceError: Error #1069

It means you have made a typo in your xml. Try to retrace your steps, what’s the last thing you’ve changed? I usually cut pieces from my code, save, and refresh the browser (caching refreshed/disabled). Still got the error? Then it’s almost certain, the code you just cut, is error free. Paste it back in or redo, and cut the next part etc. You could also comment out your code using <!-- --> But since I comment my code so much, this method doesn’t apply for me (See the part about commenting).

Once you find the part with the error in it, check for these issues:

Duplicate attributes

Do you have duplicate attributes? ex: <plugin name="test" url="image.png" keep="true" visible="true" keep="false" />

In this example you already have a keep attribute defined. Flash deals with this perfectly fine (last one overwrites the first). But Javascript (iPad) has stricter rules.

Alsoo you can’t have the same attribute name as your nodename. ex:

<plugin menu="true" name="test">
<menu name="testmenu" color="0xFFFFFF" />
</plugin>

In this example you have an attribute called menu. But later you define a sub node of the xml with the same name. plugin[test].menu references to true but alsoo to the sub node: menu[testmenu].

End with a semicolon

– Do you end every line with a semicolon ; in your actions? Careful with if statements, for loops and other commands that use a comma , to split a command in multiple parts. Place a semicolon at the end of the complete statement, after the “)”.

Close your xml tags

– Did you close every xml tag? This can be a “hard” close,  <plugin name="test"></plugin> or an inline close <plugin name="test" /> . Every xml tag needs to be closed, being an action, include or hotspot. There is no difference between a hard close or  a inline close. The only difference being, you can add code before you close a hard close. Most common seen in actions

<action name="foo">
trace("bar");
</action>

Plugins don’t require code after their tag and thus can be closed inline.

This rule also applies to includes. The xml needs a start and end tag. With Krpano, 99% of the cases this is <krpano></krpano> . When writing custom xml that needs to be included, I sometimes forget this one.

Commenting

– Be careful when commenting code. The correct way is <!– the message –> Don’t add three  dashes (-) or have comments in comments:

<!-- commented out for testing
<!-- a test plugin -->
<plugin name="test" />
 <!-- a plugin that controls fullscreen -->
<plugin name="fs" />
-->

Also don’t add comments before the initial tag (the <krpano> ) or before the XML DOCTYPE <?xml version="1.0"?>

Reserved characters

– XML has several reserved characters you cannot use in your code (http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references) You have to use their save alternative:

& - &amp;
< - &lt;
> -  &gt;
" - &quot;
' - &#39;

The & for instance is common when you add a url in the xml. Make sure it’s save encoded! Handy url that does it for you: http://www.albionresearch.com/misc/urlencode.php

Seperate attributes

– Keep attributes seperated with a space. keep="true"visible="false"  results in an error. keep="true" visible="false" doesn’t.

Other tips

If you still have troubles to find/fix your error, try dragging your xml in your browser. IE for instance tells you at which line it fails. Furthermore, this is a great online validator:

http://www.w3schools.com/xml/xml_syntax.asp
http://www.w3schools.com/xml/xml_validator.asp

Leave a Reply

Your email address will not be published.

View my portfolio!