I'm trying to add a prefix 'xml' to an XML document built with StreamingMarkupBuilder.
It seems the prefix 'xml' is simply ignored. Thanks in advance.
I would expect an occurrence of xmlns:xml='http://....' in the bulit document.
def smb = new StreamingMarkupBuilder()
def binding = smb.bind {
mkp.declareNamespace(dc: "http://purl.org/dc/elements/1.1/")
mkp.declareNamespace(xml: "http://www.w3.org/XML/1998/namespace")
greeting("hello")
}
println binding.toString()
Result:
<greeting xmlns:dc='http://purl.org/dc/elements/1.1/'>hello</greeting>
Thanks in advance.
If you change either the prefix or the URI it will be output.
def smb = new groovy.xml.StreamingMarkupBuilder()
def binding = smb.bind {
mkp.declareNamespace(dc: "http://purl.org/dc/elements/1.1/")
mkp.declareNamespace(xml: "HTTP://www.w3.org/XML/1998/namespace")
greeting("hello")
}
binding.toString()
==>
<greeting xmlns:dc='http://purl.org/dc/elements/1.1/'
xmlns:xml='HTTP://www.w3.org/XML/1998/namespace'>hello</greeting>
I don't know where in the code or why that is done.
Jim
Prystash,John wrote:
> I'm trying to add a prefix 'xml' to an XML document built with
> StreamingMarkupBuilder.
>
> It seems the prefix 'xml' is simply ignored. Thanks in advance.
> I would expect an occurrence of xmlns:xml='http://....' in the bulit
> document.
>
> def smb = new StreamingMarkupBuilder()
> def binding = smb.bind {
> mkp.declareNamespace(dc: " http://purl.org/dc/elements/1.1/
> <http://purl.org/dc/elements/1.1/> ")
> * mkp.declareNamespace(xml: " **
> http://www.w3.org/XML/1998/namespace *
> <http://www.w3.org/XML/1998/namespace>* ") *
> greeting("hello")
>
> }
> println binding.toString()
>
> Result:
>
> <greeting xmlns:dc='http://purl.org/dc/elements/1.1/'>hello</greeting>
>
> Thanks in advance.
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
org.xml.sax.SAXParseException: The prefix "xml" cannot be bound to any
namespace other than its usual namespace; neither can the namespace for
"xml" be bound to any prefix other than "xml".
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown
Source)
at
org.custommonkey.xmlunit.XMLUnit.buildDocument(XMLUnit.java:376)
at
org.custommonkey.xmlunit.XMLUnit.buildDocument(XMLUnit.java:363)
at org.custommonkey.xmlunit.Diff.<init>(Diff.java:100)
at org.custommonkey.xmlunit.Diff.<init>(Diff.java:92)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorA
ccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingCons
tructorAccessorImpl.java:27)
at
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at
org.codehaus.groovy.runtime.MetaClassHelper.doConstructorInvoke(MetaClas
sHelper.java:535)
at
groovy.lang.MetaClassImpl.doConstructorInvoke(MetaClassImpl.java:2352)
at
groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1252)
at
groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1182)
at
org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHel
per.java:805)
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeNewN(ScriptBytec
odeAdapter.java:227)
The XML namespace spec says that http://www.w3.org/XML/1998/namespace is
already bound to the prefix xml: (http://www.w3.org/XML/1998/namespace).
XmlSlurper knows this so it ignores your namespace declaration.
Actually I think that it's illegal explicitly bind a namespace to xml: even
if you try to bind http://www.w3.org/XML/1998/namespace (this is because of
the fact that xml and XML are reserved names in the original XML spec).
So the bottom line is that you don't have to (and should not) use
mkp.declareNamespace with the prefix xml. Just use the xml prefix as though
it had been previously declared and everything will work fine.
John Wilson
--
View this message in context: http://www.nabble.com/mkp.declareNamespace%28%29-ignore-prefix-%27xml%27--tp16771582p16780168.html
Sent from the groovy - user mailing list archive at Nabble.com.