Rafael
Rafael

Reputation: 35

Action Script select XML element with ':' symbol on tag name

I'm working with the Livestream API, and I need to get some XML with the desired channel info, so i'm having problem when reading the XML values with the XML object, because the tags are have the ':' symbol in the tag name, like this:

<ls:isLive>true</ls:isLive>

When I try to select like this, it obviously return me a parsing error:

xmlData.ls:isLive

And then I tried this way, but it returned me empty value:

xmlData["ls:isLive"]

How can I select this element's value by the tag name?

Upvotes: 0

Views: 150

Answers (3)

Engineer
Engineer

Reputation: 48803

Suppose your xml looks like this:

var xml:XML = <root xmlns:ls="http://blabla.com">
                 <ls:isLive>true</ls:isLive>
              </root>

To access isLive tag you need to declare Namespace:

var ls:Namespace = new Namespace("ls","http://blabla.com") ;
var isLiveTag:* = xml.ls::isLive;

Upvotes: 1

Juni Brosas
Juni Brosas

Reputation: 1486

Are you sure is what you are trying to access.. i tried using that tag but as3 is giving me an error.

I think you are accessing a wrong element name.

Names should be short and simple, like this: not like this: .

Avoid "-" characters. If you name something "first-name," some software may think you want to subtract name from first.

Avoid "." characters. If you name something "first.name," some software may think that "name" is a property of the object "first."

Avoid ":" characters. Colons are reserved to be used for something called namespaces (more later).

Upvotes: 0

Larusso
Larusso

Reputation: 1151

You are dealing with a xml namespace. In the xml header should be a definition like

xmlns:ls='http://someuri/schema'

You need to define a namespace and access the node with the namespace

I think this post will help: xml and namespace

Upvotes: 1

Related Questions