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.
- you need have default namespace, have 1 defined product element.
- 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
Post a Comment