J.Doe
J.Doe

Reputation: 9

XML, Namespaces, E4X

I have this XML file:

var k= <texta xmlns="http://www.ert.com" xmlns:ns="http://asd/asi/" xmlns:xsd="http://dgewdged" xmlns:SOAP-ENV="http://sasdfasdf" xmlns:xsi="http://asdfasdgsde">
  <textb>
    <textc>Test</textc>
  </textb>
</texta>

how can i get with E4X only the text "Test"?

var text=k.textb;
Alert(text);

I tried it on this way...but i get:

<textb xmlns="http://www.ert.com" xmlns:ns="http://asd/asi/" xmlns:xsd="http://dgewdged" xmlns:SOAP-ENV="http://sasdfasdf" xmlns:xsi="http://asdfasdgsde">
    <textc>Test</textc>
  </textb>

How can i remove the whole Namespaces ?

thank you for your help.

Upvotes: 0

Views: 441

Answers (1)

agermano
agermano

Reputation: 1729

There are several ways to access those elements.

Setting the default namespace

default xml namespace = 'http://www.ert.com';
var text = k.textb.textc.toString();
Alert(text);
// reset to empty namespace
default xml namespace = '';

Using an explicit namespace

var ert = new Namespace('http://www.ert.com');
var text = k.ert::textb.ert::textc.toString();
Alert(text);

Using namespace wildcards

var text = k.*::textb.*::textc.toString();
Alert(text);

Upvotes: 1

Related Questions