I am trying to access an XMLList item and convert it to am XML object.
I am using this expression:
masonicXML.item.(@style_number == styleNum)
For example if there is a match everything works fine but if there is not a match then I get an error when I try cast it as XML saying that it has to be well formed. So I need to make sure that the expression gets a match before I cast it as XML. I tried setting it to an XMLList variable and checking if it as a text() propertie like this:
var defaultItem:XMLList = DataModel.instance.masonicXML.item.(@style_number == styleNum); if(defaultItem.text()) { DataModel.instance.selectedItem = XML(defaultItem); }
But it still give me an error if theres no match. It works fine if there is a match.
THANKS!
In my experience, the simplest way to check for results is to grab the 0th element of the list and see if it’s
null.Here is your code sample with a few tweaks. Notice that I’ve changed the type of
defaultItemfromXMLListtoXML, and I’m assigning it to the 0th element of the list.