Expand my Community achievements bar.

E4X XML function hasOwnProperty() doesn't work as filter

Avatar

Level 8

I am trying to filter XML (based on E4X syntax) to get list of items with certain attribute value. Some of the XML Elements don't have that specific attribute.

See example below:

var xmlDoc =

<tran>

   <label>

      <somExp>$parent$.client_email[0]</somExp>

      <caption_en>E-MAIL:</caption_en>

      <caption_fr>COURRIEL:</caption_fr>

   </label>

   <label>

      <somExp>$parent$.lb_appraiser_vertical</somExp>

      <caption_en>APPRAISER</caption_en>

      <caption_fr>APPRAISER</caption_fr>

   </label>

   <label>

      <somExp>$parent$.appraiser_name[0]</somExp>

      <caption_en >APPRAISER:</caption_en>

      <caption_fr >ÉVALUATEUR:</caption_fr>

      <caption_en >APPRAISER:</caption_en>

      <caption_fr qual="EA">ÉVALUATEUR:</caption_fr>

      <caption_en qual="AIC">AIC Member:</caption_en>

      <caption_fr qual="AIC">MEMBRE DE L’ICE:</caption_fr>

    </label>

</tran>;

var list = xmlDoc.label;

app.alert(list[2].caption_en); //Works fine

list[2].caption_en.@qual; //Works fine ===> "AIC"

list[2].caption_en.(@qual == "AIC"); //Throws error reference to undefined XML name @qual

list[2].caption_en.(hasOwnProperty("@qual")); //Throws error can't convert undefined to object

list[2].caption_en.hasOwnProperty("@qual"); //Works fine and gives you "true"

Basically, I need the above to provide two different translations for a given caption, based on form-type qualifier: "AIC" or "EA", for English and French.

I did research this, and found out that I can use "hasOwnProperty()" function for this purpose. But, it doesn't work as a filter. Because, not all elements need to have this "@qual" attribute. If all caption elements have "@qual" attribute, then it will work fine.

To test the above, open Acrobat PDF, press ctrl-j and try the above using the console.

Do you have any suggestions to resolve the above?

I think now the only way is to use for loop over "list[2].caption_en"and test each element using functions "hasOwnAttribute()" or "attribute()".

Tarek

0 Replies