how to get xmlns attribute of root node in the document

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
shikhar_472
Posts: 99
Joined: Fri Jul 01, 2022 12:08 pm

how to get xmlns attribute of root node in the document

Post 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.
Bogdan Dumitru
Site Admin
Posts: 142
Joined: Tue Mar 20, 2018 5:28 pm

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

Post 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()".
Bogdan Dumitru
http://www.oxygenxml.com
Bogdan Dumitru
Site Admin
Posts: 142
Joined: Tue Mar 20, 2018 5:28 pm

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

Post by Bogdan Dumitru »

Bogdan Dumitru
http://www.oxygenxml.com
Post Reply