How can I check for the existence of an XML node in Flex/AS3? -


For each recurrence, false detects trace in the loop given below, even if there Nodes are named with 6 out of 8 possible values ​​??? It only happens when my name is in place. Is there any other way to check node values?

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Mx: application xmlns: mx = "http://www.adobe.com/2006/mxml" layout = "full" & gt; & Lt; Mx: script & gt; & Lt ;! [CDATA [Private namespace ltrs = "letters"; Use namespace liter; Private variable myArray: array = ["A", "B", "C", "D", "E", "F", "G", "H"]; Private Function CheckXML (): Zero {for each (var p: string in miere) {trace (myXML.hasOwnProperty (p) .toString ()); // false return; }}]] & Gt; & Lt; / Mx: script & gt; & Lt; Mx: XML id = "myXML" & gt; & Lt; Root xmlns = "letters" & gt; & Lt; A & gt; True & lt; / A & gt; & Lt; P & gt; True & lt; / P & gt; & Lt; C & gt; True & lt; / C & gt; & Lt; E & gt; True & lt; / E & gt; & Lt; F & gt; True & lt; / H> & Lt; Ch & gt; True & lt; / G> & Lt; / Root & gt; & Lt; / Mx: xml> & Lt; Mx: button click = "check xml ();" / & Gt; & Lt; / Mx: Applications & gt;  

The method does not work with just the XML nodes I believe Although it is for the E4X specification, you can always ask for a node with E4X, even if it is not there and just see what the length of the XMLList is that you come back like this:

  trace (myXML [P]; length ());  

EDIT: As mentioned below, I was wrong about the hasOwnProperty bit. It works with XML, and it's a namespace issue that is causing your problem. You can make sure that your XML is using the correct namespace using this handy snippet:

  if (myXML.namespace ("")! = Undefined) {default xml Namespace = myXML.namespace (""); }  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -