windbrand1
windbrand1

Reputation: 5

Actionscript 3 - XML syntax?

Does anyone know how the XML syntax works in Actionscript 3? I copied over my XML file into AS so I can export an independent SWF, but it's giving me a whole bunch of syntax errors "1093: syntax error", on almost every single line.

var xml:XML = 
<images>
    <pic>images/3.png</pic>
    <painter>Painter name</painter>
    <title>画家1</title>
    <date></date>
</images>
<images>
    <pic>images/2.png</pic>
    <painter>Painter name</painter>
    <title>画家2</title>
    <date></date>
</images>
...
...
about 20 of these <images> sections

One of the parameters contains foreign characters. I've already tried turning all the "<" ">" and quotation/apostrophes into the HTML code, still doesn't work...

Thanks.

Upvotes: 0

Views: 80

Answers (1)

sberry
sberry

Reputation: 131978

You need a root node. That is not valid xml as it stands right now.

An easy fix is to just wrap the <images> nodes in a <root> node like so

val xml:XML = 
<root>
    <images>
        <pic>images/3.png</pic>
        <painter>Painter name</painter>
        <title>画家1</title>
        <date></date>
    </images>
    ...
</root>

If you want your XML to map directly to an XMLList, you can use an unnamed root node (*note this is not valid XML, but AS3 doesn't mind)

<>
    <images>
        <pic>images/3.png</pic>
        <painter>Painter name</painter>
        <title>画家1</title>
        <date></date>
    </images>
    ...
</>

Upvotes: 2

Related Questions