pradeepsjsu / beanio

Automatically exported from code.google.com/p/beanio
Apache License 2.0
0 stars 0 forks source link

Can't override the default XML namespace #32

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Even if I set xmlPrefix="" on a bean, it still uses the defined namespace 
prefix. I want to use the default namespace to write the bean "series".

Config file:
<stream name="ScoresXML" format="xml" xmlType="none">
 <writer>
  <property name="version" value="1.0"/>
  <property name="encoding" value="UTF-8"/>
  <property name="indentation" value="1"/>
  <property name="lineSeparator" value="&#xA;"/>
  <property name="namespaces" value="
   d urn:oid:1.3.6.1.4.1.39777.1.0.1.0
   xml http://www.w3.org/XML/1998/namespace
   xsi http://www.w3.org/2001/XMLSchema-instance
  "/>
 </writer>
 <record name="cursus" class="eu.lp0.cursus.xml.scores.ScoresXML" xmlPrefix="" xmlNamespace="urn:oid:1.3.6.1.4.1.39777.1.0.1.1">
  <field name="generator" xmlType="attribute" xmlNamespace=""/>
  <bean name="series" minOccurs="1" class="eu.lp0.cursus.xml.data.entity.DataXMLSeries" xmlPrefix="" xmlNamespace="urn:oid:1.3.6.1.4.1.39777.1.0.1.0">
   <include template="series"/>
  </bean>
  <bean name="seriesResults" minOccurs="0" class="eu.lp0.cursus.xml.scores.results.ScoresXMLSeriesResults">
   <include template="seriesResults"/>
  </bean>
  <bean name="eventResults" minOccurs="0" maxOccurs="unbounded" class="eu.lp0.cursus.xml.scores.results.ScoresXMLEventResults" collection="list">
   <include template="eventResults"/>
  </bean>
  <bean name="raceResults" minOccurs="0" maxOccurs="unbounded" class="eu.lp0.cursus.xml.scores.results.ScoresXMLRaceResults" collection="list">
   <include template="raceResults"/>
  </bean>
 </record>
</stream>

Expected output:
<?xml version="1.0" encoding="UTF-8"?>
<cursus xmlns="urn:oid:1.3.6.1.4.1.39777.1.0.1.1" 
xmlns:d="urn:oid:1.3.6.1.4.1.39777.1.0.1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" generator="cursus 0.0.1">
 <series xml:id="Seriesa1464332ac848" xmlns="urn:oid:1.3.6.1.4.1.39777.1.0.1.0">
  <name>...

Actual output:
<?xml version="1.0" encoding="UTF-8"?>
<cursus xmlns="urn:oid:1.3.6.1.4.1.39777.1.0.1.1" 
xmlns:d="urn:oid:1.3.6.1.4.1.39777.1.0.1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" generator="cursus 0.0.1">
 <d:series xml:id="Seriesa1464332ac848">
  <d:name>...

Original issue reported on code.google.com by goo...@sa.me.uk on 22 Apr 2012 at 5:09

GoogleCodeExporter commented 9 years ago
Hi Simon,

The easiest solution may be to remove the namespace declaration from the 
writer's "namespaces" property.  Is there any reason you declared it there if 
you didn't want to use a "d" prefix?

Thanks,
Kevin

Original comment by kevin.s...@gmail.com on 22 Apr 2012 at 9:40

GoogleCodeExporter commented 9 years ago
Yes, I refer to that namespace later on (lines 141 and 155).

Original comment by goo...@sa.me.uk on 22 Apr 2012 at 9:56

Attachments:

GoogleCodeExporter commented 9 years ago
Unfortunately, some DOM implementations do not accept empty string prefixes, so 
the fix will not be as easy as I had hoped, but it can be done...

Original comment by kevin.s...@gmail.com on 23 Apr 2012 at 2:21

GoogleCodeExporter commented 9 years ago
Fixed for 1.2.5.

Please try the attached 1.2.5-snapshot JAR and let me know if you have any 
issues.

Original comment by kevin.s...@gmail.com on 29 Apr 2012 at 4:11

Attachments:

GoogleCodeExporter commented 9 years ago
I'm using 2.0.0.M1 so I can't test that as the config file isn't compatible.

Original comment by goo...@sa.me.uk on 29 Apr 2012 at 11:35

GoogleCodeExporter commented 9 years ago
 Ok, try this 2.x snapshot JAR.  For the record, your mapping file in the defect report is a 1.x mapping file.  

Original comment by kevin.s...@gmail.com on 30 Apr 2012 at 4:04

Attachments:

GoogleCodeExporter commented 9 years ago
It does something odd at the start with what should be the default namespace:
<zdef-247938963:cursus xmlns="" xmlns:d="urn:oid:1.3.6.1.4.1.39777.1.0.1.0.1" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:zdef-247938963="urn:oid:1.3.6.1.4.1.39777.1.0.1.1.1" generator="cursus 
0.0.1" xsi:schemaLocation="urn:oid:1.3.6.1.4.1.39777.1.0.1.0.1 
https://xsd.s85.org/urn/oid/1.3.6.1.4.1.39777.1.0.1.0.1 
urn:oid:1.3.6.1.4.1.39777.1.0.1.1.1 
https://xsd.s85.org/urn/oid/1.3.6.1.4.1.39777.1.0.1.1.1">

After the element with the modified default namespace, there should be other 
elements with the original default namespace but these are all in 
zdef-247938963.

Original comment by goo...@sa.me.uk on 30 Apr 2012 at 12:58

GoogleCodeExporter commented 9 years ago
Alright, sorry for the delay, please try the attached 2.x snapshot JAR.

Original comment by kevin.s...@gmail.com on 4 May 2012 at 3:40

Attachments:

GoogleCodeExporter commented 9 years ago
It's almost correct but now the series element has an empty xmlns:
<cursus xmlns="urn:oid:1.3.6.1.4.1.39777.1.0.1.1.1" 
xmlns:d="urn:oid:1.3.6.1.4.1.39777.1.0.1.0.1" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" generator="cursus 0.0.1" 
xsi:schemaLocation="urn:oid:1.3.6.1.4.1.39777.1.0.1.0.1 
https://xsd.s85.org/urn/oid/1.3.6.1.4.1.39777.1.0.1.0.1 
urn:oid:1.3.6.1.4.1.39777.1.0.1.1.1 
https://xsd.s85.org/urn/oid/1.3.6.1.4.1.39777.1.0.1.1.1">
 <series xmlns="" xml:id="Seriesf226ee0c4130">

All of the other elements are ok, including the use of d: later on in the file.

(Tested http://beanio.googlecode.com/svn/trunk@116 instead of the .jar as I 
assume they're the same)

Original comment by goo...@sa.me.uk on 4 May 2012 at 8:44

GoogleCodeExporter commented 9 years ago
Would you mind posting a simpler mapping file that recreates the latest issue?  
Thanks!

Original comment by kevin.s...@gmail.com on 4 May 2012 at 9:32

GoogleCodeExporter commented 9 years ago
I've tried to recreate the issue with the following sample, but did not have 
any luck.

  <template name="segment">
    <field name="firstName" />
    <field name="lastName" />
  </template>

  <stream name="stream11" format="xml" xmlType="none">
    <parser>
      <property name="indentation" value="2" />
      <property name="namespaces" value="
        s   urn:segment
        xsi http://www.w3.org/2001/XMLSchema-instance" />
    </parser>
    <record name="person" class="map" xmlNamespace="urn:record" xmlPrefix="">
      <field name="schemaLocation" ignore="true" 
        default="urn:segment https:/blah.com/segment" 
        xmlType="attribute" xmlNamespace="http://www.w3.org/2001/XMLSchema-instance"/>
      <field name="generator" xmlType="attribute" xmlNamespace=""/>
      <segment name="segment" minOccurs="1" class="map" xmlNamespace="urn:segment" xmlPrefix="">
        <include template="segment" />
      </segment>
    </record>
  </stream>

Original comment by kevin.s...@gmail.com on 13 May 2012 at 12:32

GoogleCodeExporter commented 9 years ago
This issue is closed until further evidence is provided. 

Original comment by kevin.s...@gmail.com on 26 May 2012 at 7:57

GoogleCodeExporter commented 9 years ago
The attached test case reproduces the empty xmlns issue:

org.junit.ComparisonFailure: expected:<...
  <address xmlns="[urn:record]" e:city="San Franci...> but was:<...
  <address xmlns="[]" e:city="San Franci...>
    at org.junit.Assert.assertEquals(Assert.java:125)
    at org.junit.Assert.assertEquals(Assert.java:147)
    at org.beanio.parser.xml.XmlParserTest.assertXmlEquals(XmlParserTest.java:59)
    at org.beanio.parser.xml.namespace.XmlNamespaceTest.testEmptyPrefix3(XmlNamespaceTest.java:379)

Original comment by goo...@sa.me.uk on 5 Aug 2012 at 10:16

Attachments:

GoogleCodeExporter commented 9 years ago
This still isn't fixed in 2.0.2

Original comment by goo...@sa.me.uk on 15 Dec 2012 at 9:16

GoogleCodeExporter commented 9 years ago
Thanks Simon, I have incorporated your test cases and am looking into the issue.

Original comment by kevin.s...@gmail.com on 15 Dec 2012 at 9:08

GoogleCodeExporter commented 9 years ago
Hi Simon,

I've attached a snapshot JAR that passes all test cases.  I had to make some 
significant changes to the way namespace are written out, so any regression 
testing you could do against the JAR would be greatly appreciated.

Thanks,
Kevin

Original comment by kevin.s...@gmail.com on 19 Dec 2012 at 3:27

Attachments:

GoogleCodeExporter commented 9 years ago
Yes, it fixes the empty xmlns issue and the rest of the XML output is the same 
as it was before. Thanks.

Original comment by goo...@sa.me.uk on 19 Dec 2012 at 8:57

GoogleCodeExporter commented 9 years ago
Fixed in release 2.0.3.

Original comment by kevin.s...@gmail.com on 22 Dec 2012 at 4:25