Copy link to clipboard
Copied
Hi all,
When I am using the below code, It will produce the output.
//Working
var myXML = new XML("<tags><tag type=\"a\">name</tag></tags>");
var typeATags = myXML.xpath("//tag[@type]").attributes();
While, Change the code with namespace. The below code is get an error.
//Not working
var myXML = new XML("<oasis:tags><oasis:tag type=\"a\">name</oasis:tag></oasis:tags>"); //Error at this line
var typeATags = myXML.xpath("//oasis:tag[@type]").attributes();
Please give any helps!!
thanks,
John.
You are missing the xmlns.
var myXML = new XML("""
<oasis:tags xmlns:oasis="http://docs.oasis-open.org/ns/oasis-exchange/table"><oasis:tag type="a">name</oasis:tag></oasis:tags>
""");
Note that I'm also using the special syntax of three double-quotes for a multi-line string, in order to avoid escaping inside.
You can also omit the whole "new XML" and inline the actual XML:
...var myXML = <oasis:tags xmlns:oasis="http://docs.oasis-open.org/ns/oasis-exchange/table"><oasis:tag type="a">name</oasis:tag></oas
Copy link to clipboard
Copied
You are missing the xmlns.
var myXML = new XML("""
<oasis:tags xmlns:oasis="http://docs.oasis-open.org/ns/oasis-exchange/table"><oasis:tag type="a">name</oasis:tag></oasis:tags>
""");
Note that I'm also using the special syntax of three double-quotes for a multi-line string, in order to avoid escaping inside.
You can also omit the whole "new XML" and inline the actual XML:
var myXML = <oasis:tags xmlns:oasis="http://docs.oasis-open.org/ns/oasis-exchange/table"><oasis:tag type="a">name</oasis:tag></oasis:tags>;
Copy link to clipboard
Copied
Hi Dirk Becker,
It is working for me.. Thanks a lot..
Thanks,
John.