Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • JDK version and platform:
      Sun 1.4.2_08 for Windows

      Description

      Hi,

      I've seen that last release of XStream now support namespaces. In fact it seems that namespace support is only partial. Indeed, XStream seems to handle only global namespace (namespace on XML root element):
      I'd like to know if it was possible to handle namespace for each XML markup ??

      Here is my code for a cleaner explanation :

      import javax.xml.namespace.QName;

      import com.thoughtworks.xstream.XStream;
      import com.thoughtworks.xstream.io.xml.QNameMap;
      import com.thoughtworks.xstream.io.xml.StaxDriver;

      public class xstreamtest {
      public static void main(String[] args)

      { QNameMap nsm = new QNameMap(); nsm.registerMapping(new QName("http://www.toto.com", "Personne"), Personne.class); nsm.registerMapping(new QName("http://imported.ns.com", "test1"), Adresse.class); nsm.registerMapping(new QName("http://imported2.ns.com", "test2"), Adresse1.class); StaxDriver d = new StaxDriver(nsm); XStream xs = new XStream(d); Adresse1 adresse1 = new Adresse1(); adresse1.field1 = 1; adresse1.field2 = "field2"; adresse1.field3 = "rue des lilas"; adresse1.field4 = 4; adresse1.field5 = "field5"; Adresse adresse = new Adresse(); adresse.CodePostal= 12; adresse.Numero = 13; adresse.NomRue = "rue des lilas"; adresse.Ville= "paris"; adresse.Personne = adresse1; Personne p = new Personne(); p.Adresse = adresse; p.Nom = "pipo"; p.Prenom = "roger"; System.out.println(xs.toXML(p)); }

      }

      Here is the code output (with some handmade beautification cause Stax writer doesn't seem to handle pretty printer =) ):
      <?xml version="1.0" encoding="utf-8"?>
      <Personne xmlns="http://www.toto.com">
      <Nom>pipo</Nom>
      <Prenom>roger</Prenom>
      <Adresse>
      <Numero>13</Numero>
      <NomRue>rue des lilas</NomRue>
      <CodePostal>12</CodePostal>
      <Ville>paris</Ville>
      <Personne>
      <field1>1</field1>
      <field2>field2</field2>
      <field3>rue des lilas</field3>
      <field4>4</field4>
      <field5>field5</field5>
      </Personne>
      </Adresse>
      </Personne>

      As you can see, the Root markup namespace is set (on Personne) but this output is not the expected one :

      First, other markup like "Adresse" and "Personne" should be "namespaced"
      Second, Address should have been serialized as "test1" and "Personne" as "test2"
      The correct output have to look like this (i guesss):
      <?xml version="1.0" encoding="utf-8"?>
      <Personne xmlns="http://www.toto.com">
      <Nom>pipo</Nom>
      <Prenom>roger</Prenom>
      <test1 xmlns="http://www.imported.ns.com">
      <Numero>13</Numero>
      <NomRue>rue des lilas</NomRue>
      <CodePostal>12</CodePostal>
      <Ville>paris</Ville>
      <test2 xmlns="http://www.imported2.ns.com">
      <field1>1</field1>
      <field2>field2</field2>
      <field3>rue des lilas</field3>
      <field4>4</field4>
      <field5>field5</field5>
      </test2>
      </test1>
      </Personne>

      Can anyone help me with this strange behavior ??

      Regards
      BQ.

        People

        • Assignee:
          Unassigned
          Reporter:
          Bertrand Quenin
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: