[XOM-interest] Why is XOM adding xmlns="" to elements?

Michael Kay mike at saxonica.com
Sun Jun 10 17:20:04 EDT 2007


If you want the element responseDeclaration to be in the namespace
http://www.imsglobal.org/xsd/imsqti_v2p1, then you must put it in that
namespace. It won't go in that namespace simply because that's the namespace
of its parent. The xmlns="" is being added because responseDeclaration, the
way you created it, is in no namespace.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: xom-interest-bounces at lists.ibiblio.org 
> [mailto:xom-interest-bounces at lists.ibiblio.org] On Behalf Of 
> Jean Pierre Malrieu
> Sent: 10 June 2007 21:52
> To: xom-interest at lists.ibiblio.org
> Subject: [XOM-interest] Why is XOM adding xmlns="" to elements?
> 
> Hi,
> 
> As you will discover very soon, I know very little about XML 
> and XML schemas...
> I want to use XOM to generate xml documents, because XOM 
> seems to be easier to understand than other APIs.
> 
> My documents must look like this:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
>      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>      xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1
> imsqti_v2p1.xsd"
> 	title = "title">
>      <responseDeclaration>
>          blabla
>      </responseDeclaration>
> </assessmentItem>
> 
> Therefore I have tried to write the following java code:
> 
> Element root = new Element("assessmentItem"); 
> root.setNamespaceURI("http://www.imsglobal.org/xsd/imsqti_v2p1");
> root.addNamespaceDeclaration("xsi","http://www.w3.org/2001/XMLSchema-
> instance");
> root.addAttribute(new Attribute("xsi:schemaLocation", 
> "http:// www.w3.org/2001/XMLSchema-instance", 
> "http://www.imsglobal.org/xsd/
> imsqti_v2p1 imsqti_v2p1.xsd"));
> root.addAttribute(new Attribute("title,"title")); Element rp 
> = new Element("responseDeclaration");
> 
> but this leads to an output like:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <assessmentItem
>      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	title = "title"
>      xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1
> imsqti_v2p1.xsd"
> 	xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1">
>      <responseDeclaration xlmns="">
>          blabla
>      </responseDeclaration>
> </assessmentItem>
> 
> which is not valid.
> How do I get rid of the xmlns="" in the responseDeclaration element?
> 
> Thanks.
> 
> JPM
> 
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> XOM-interest mailing list
> XOM-interest at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/xom-interest



More information about the XOM-interest mailing list