Page 1 of 1

how to get xmlns attribute of root node in the document

Posted: Thu Jun 22, 2023 11:13 am
by shikhar_472
Hi All,

Below are two types of XML which we use with the web Author ,

Xml Type 1:
<n-load xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.application.com/product/document http://applicatiom.subnet/AppInstance/r ... cument.xsd">
.... xml content here
</n-load>

Xml type 2
<xampex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.application.com/product/xampex http://applicatiom.subnet/XampexInstanc ... xampex.xsd">
..... xml content here
</xampex>

In our custom functionality we want to get schemalocation value from the root element. From web author UI, we have seen schema location value of the above xml stored in xmlns attribute.
We are using below code snippet to fetch xmlns attribute that we are getting null value.

authorDocumentModel..getAuthorDocumentController().getAuthorDocumentNode().getNamespace();

Can you please let us know how we can get the xmlns attribute details from the root element.

Thanks.

Re: how to get xmlns attribute of root node in the document

Posted: Thu Jun 22, 2023 12:39 pm
by Bogdan Dumitru
Hello,

I think you're making a confusion here - you say "we want to get schemalocation value from the root element" but you call "getNamespace" method. The "getNamespace" returns the namespace of the element (the "xmlns" attribute value).

To retrieve the "xsi:schemaLocation" value you have to use ro.sync.ecss.extensions.api.node.AuthorElement.getAttribute(String) method: authorDocumentModel.getAuthorDocumentController().getAuthorDocumentNode().getRootElement().getAttribute("xsi:schemaLocation")

If you need the namespace of the root element you have to use "authorDocumentModel.getAuthorDocumentController().getAuthorDocumentNode().getRootElement().getNamespace()" instead of "authorDocumentModel.getAuthorDocumentController().getAuthorDocumentNode().getNamespace()".

Re: how to get xmlns attribute of root node in the document

Posted: Fri Jul 28, 2023 11:59 am
by Bogdan Dumitru