0

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.

J.Doe
  • 9
  • 2
  • E4X has been deprecated since 2014. I don't think I even have any software capable of running it these days. I'd strongly suggest switching to something else to process your XML. – Quentin Nov 09 '18 at 10:25

1 Answers1

1

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);
agermano
  • 1,679
  • 6
  • 16