Details
-
Type: Bug
-
Status: Closed
-
Priority: 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)
}
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.
As far as I can see this works, but you have to register the corrent tags for the namespaces. See testUsingDifferentNamespacesWithAliases in http://svn.xstream.codehaus.org/trunk/xstream/src/test/com/thoughtworks/acceptance/QNameMappedConcreteClassesTest.java?rev=689&view=markup.