History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GROOVY-2784
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Wayne Keenan
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
groovy

XmlNodePrinter namespace declarations are inserted at incorrect scope

Created: 27/Apr/08 10:49 AM   Updated: 08/May/08 01:07 PM
Component/s: groovy-jdk, XML Processing
Affects Version/s: 1.5.5, 1.5.6
Fix Version/s: 1.5.7, 1.6-beta-2

Time Tracking:
Not Specified

File Attachments: 1. XML File test.xml (0.2 kb)
2. XML File testout.xml (0.2 kb)
3. File XmlNodePrintNamespaceTestCase.groovy (0.4 kb)
4. File XmlNodePrintNamespaceTestCase2.groovy (0.6 kb)

Environment: groovy 1.5.6, windows xp java 1.5


 Description  « Hide
When outputting a document with namespaces the namespace declarations are created at the wrong 'scope' / 'level' in the document.
The attache Groovy script show that parsing back in a document just created by XmlNodePrinter demostrates this .

Please see attached and error below:

[Fatal Error] testout.xml:7:10: The prefix "ns1" for element "ns1:b" is not bound.
Exception in thread "main" org.xml.sax.SAXParseException: The prefix "ns1" for element "ns1:b" is not bound.
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at groovy.util.XmlParser.parse(XmlParser.java:115)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:599)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:740)
at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:761)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:749)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:167)
at TestPackage.XmlNodePrintNamespaceTestCase.run(XmlNodePrintNamespaceTestCase.groovy:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:599)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:740)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:773)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:753)
at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:402)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:95)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:599)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1077)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:744)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:167)
at TestPackage.XmlNodePrintNamespaceTestCase.main(XmlNodePrintNamespaceTestCase.groovy)



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul King - 06/May/08 09:39 AM
possibly related to GROOVY-2810

Wayne Keenan - 06/May/08 10:48 AM
I have reduced my original attachments to a minimal self contained GroovyUnit test case, XmlNodePrintNamespaceTestCase2.groovy

For the here-doc input:

def inputXml = '''<a xmlns:ns1="urn:myns1">
<ns1:b1>
</ns1:b1>
<ns1:b2>
</ns1:b2>
</a>
'''

The output is:

XmlParser Dump: a[attributes={}; value=[{urn:myns1}b1[attributes={}; value=[]], {urn:myns1}b2[attributes={}; value=[]]]]
XmlNodePrinter Dump: <a>
<ns1:b1 xmlns:ns1="urn:myns1"/>
<ns1:b2/>
</a>

[Fatal Error] :3:12: The prefix "ns1" for element "ns1:b2" is not bound.