xml - Filter element by attribute with namespace in E4X -


i have xml this:

<product xmlns="http://www.example-schame.org" product-id="5555555">     <display-name xml:lang="x-default">default name</display-name>     <display-name xml:lang="en-gb">english name</display-name>     <display-name xml:lang="it-it">italian name</display-name> </product> 

i want default name, e.g. 1 attribute xml:lang="x-default".

i tried as

var name = product["display-name"].(@["xml:lang"] == "x-default"); 

but returns me undefined. ideas?

you missing namespaces.

  1. you need have default namespace, have 1 defined product element.
  2. you need have xml namespace, lang attribute of namespace

here sample code

var product = <product xmlns="http://www.example-schame.org" product-id="5555555">     <display-name xml:lang="x-default">default name</display-name>     <display-name xml:lang="en-gb">english name</display-name>     <display-name xml:lang="it-it">italian name</display-name> </product>;  default xml namespace = product.namespace(); var xmlns = new namespace("xml", "http://www.w3.org/xml/1998/namespace"); var name = product["display-name"].(@xmlns::lang == "x-default"); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -