Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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


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 =














      <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>



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()".


0 Replies