0

I am trying to find which of the following "object" nodes contains a url within the linkurl attribute. The linkurl attribute will always be there even if there is no content within the attribute. I'm not having any luck because I can;t find a way to determine if the first instance of the linkurl in the first object node is empty, and move on to the second and then third etc. The attribute always contains something even if there is no content in the attribute itself.

This is the xml

<object id='graphic1' active='1' url='media/00360691.swf' x='445' y='125' alt='' altfr='' altes='' tabIndex='1' layer='0' linkurl=''/>
<object id='graphic2' active='0' url='media/00360691.swf' x='0' y='0' alt='' altfr='' altes='' tabIndex='1' layer='0' linkurl='html/AnalyticalReviewAnalysis.pdf'/>
<object id='graphic3' active='0' url='media/00360692.swf' x='0' y='0' alt='' altfr='' altes='' tabIndex='1' layer='0' linkurl=''/>
<object id='graphic4' active='0' url='media/00360693.swf' x='0' y='0' alt='' altfr='' altes='' tabIndex='1' layer='0' linkurl=''/>
<object id='graphic5' active='0' url='media/' x='0' y='0' alt='' altfr='' altes='' tabIndex='1' layer='0' linkurl=''/>
<object id='activity' active='0' url='media/' x='0' y='0'/>

This is what I have tried so far:

if(myXML.object[7].hasOwnProperty("@linkurl")){
        trace("graphic 1 is not empty");
        linkURL = myXML.object[7].attribute("linkurl")[0];
} else {
        trace("graphic 1 is empty");
}

    trace("length: "+myXML.object[7].attribute("linkurl")[0].length());
    trace(myXML.object[7].attribute("linkurl")[0]);

    trace("linkURL: "+ linkURL);

This is what traces:

graphic 1 is not empty
length: 1

linkURL: 

The length is always 1 regardless of whether the attribute contains content or does not. Thus, I have no way to disregard the empty node, and move on to the next one. The if statement always comes up not empty, because even if linkurl="", it still has something.

2 Answers 2

1

Try this:

if ( myXML.object[7].@linkurl && myXML.object[7].@linkurl != '' ) {
    // linkurl contains data
}
else {
    // linkurl is empty
}

Basically you verify the linkurl property actually exists (this is just a good practice to avoid null refs) and see if the string is not an empty string. If that's true, you can set your AS3 linkurl property. Otherwise, you ignore it.

Sign up to request clarification or add additional context in comments.

Comments

1

The length of 1 is correct - you have 1 linkurl attribute in your xml object.

An attribute with an empty string as its value is still an attribute

To get a length of zero, the xml should not contain linkurl='' at all

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.