Re: [Simple-support] Deserialisation of XML document with multiple namespaces
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2011-05-11 12:17:31
|
To avoid this declare all elements with the same name as entries of the same inline element. This should work for you. All you have to do is keep track of the element names being traversed.
--- On Tue, 10/5/11, Dave Mellors <dav...@gm...> wrote:
From: Dave Mellors <dav...@gm...>
Subject: Re: [Simple-support] Deserialisation of XML document with multiple namespaces
To: sim...@li...
Received: Tuesday, 10 May, 2011, 9:12 AM
Hmm,
I have been trying this, and have used the Visitor implementation
elsewhere, but the exception being thrown regarding the
'sub_element' element being declared twice happens before the
visitor, (and a default VisitorStrategy) has an opportunity to
intercept the processing.
The stack trace is thus...
org.simpleframework.xml.core.PersistenceException: Element 'thing'
declared twice at line 10
at
org.simpleframework.xml.core.Variable$Adapter.read(Variable.java:444)
at
org.simpleframework.xml.core.Variable$Adapter.read(Variable.java:422)
at
org.simpleframework.xml.core.Composite.readVariable(Composite.java:679)
at
org.simpleframework.xml.core.Composite.readInstance(Composite.java:627)
at
org.simpleframework.xml.core.Composite.readUnion(Composite.java:602)
at
org.simpleframework.xml.core.Composite.readElement(Composite.java:585)
at
org.simpleframework.xml.core.Composite.readElements(Composite.java:502)
at
org.simpleframework.xml.core.Composite.readSection(Composite.java:388)
at
org.simpleframework.xml.core.Composite.read(Composite.java:368)
at
org.simpleframework.xml.core.Composite.readDefault(Composite.java:262)
at
org.simpleframework.xml.core.Composite.read(Composite.java:232)
at
org.simpleframework.xml.core.Composite.read(Composite.java:202)
at
org.simpleframework.xml.core.Composite.read(Composite.java:150)
at
org.simpleframework.xml.core.Composite.readVariable(Composite.java:679)
at
org.simpleframework.xml.core.Composite.readInstance(Composite.java:627)
at
org.simpleframework.xml.core.Composite.readUnion(Composite.java:602)
at
org.simpleframework.xml.core.Composite.readElement(Composite.java:585)
at
org.simpleframework.xml.core.Composite.readElements(Composite.java:502)
at
org.simpleframework.xml.core.Composite.readSection(Composite.java:388)
at
org.simpleframework.xml.core.Composite.read(Composite.java:368)
at
org.simpleframework.xml.core.Composite.readDefault(Composite.java:262)
at
org.simpleframework.xml.core.Composite.read(Composite.java:232)
at
org.simpleframework.xml.core.Composite.read(Composite.java:202)
at
org.simpleframework.xml.core.Composite.read(Composite.java:150)
at
org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
at
org.simpleframework.xml.core.Persister.read(Persister.java:632)
at
org.simpleframework.xml.core.Persister.read(Persister.java:613)
at
org.simpleframework.xml.core.Persister.read(Persister.java:591)
at
org.simpleframework.xml.core.Persister.read(Persister.java:550)
at
test.SimpleXmlDeserialisationTest.loadXml(SimpleXmlDeserialisationTest.java:40)
...
The problem appears to be that the stack of registered elements does
not take into account the namespace, and I cannot see how you can
deal with this. Should this really be an enhancement/bug, as the
XML is perfectly valid.
For the moment I have managed to find a potential work around, by
declaring just one java class as a list of inline elements, and then
resolving what I need to do at validate/commit time as necessary.
Regards
Dave Mellors
Subject:
Re: [Simple-support] Deserialisation of XML document with
multiple namespaces
From:
Niall Gallagher <gal...@ya...>
Date:
Mon, 9 May 2011 19:38:08 -0700 (PDT)
To:
sim...@li..., Dave Mellors
<dav...@gm...>
You will have to use a Visitor for this. This will allow you to apply namespaces without the use of annotations. There are examples of Visitors in the test cases and in the tutorial.
--- On Mon, 9/5/11, Dave Mellors <dav...@gm...> wrote:
> From: Dave Mellors <dav...@gm...>
> Subject: [Simple-support] Deserialisation of XML document with multiple namespaces
> To: sim...@li...
> Received: Monday, 9 May, 2011, 9:43 AM
> Hi,
>
> I am attempting to read an xml document which has common
> element names
> across namespaces.
>
> <content>
> <element>
> <name/>
> <xy1:sub_element xmlns:xy1="http://www.xxx.com">
> <xy1:detail_1/>
> <xy1:detail_2/>
> </xy1:sub_element>
> <xy2:sub_element xmlns:xy2="http://www.yyy.com">
> <xy2:something_else/>
> <xy2:something_different/>
> </xy2:sub_element>
> </element>
> </content>
>
> I have tried many ways to resolve this, but come up with
> errors which
> ever way I go, e.g. duplicate annotation in the java class
>
> public class XmlElement {
>
> private String
> name;
>
>
> @Element(name="sub_element")
>
> @Namespace(prefix="xy1", reference="http://www.xxz.com)")
> private ThingOne
> thingOne;
>
>
> @Element(name="sub_element")
>
> @Namespace(prefix="xy2", reference="http://www.xxz.com)")
> private ThingTwo
> thingTwo;
> }
>
> Any ideas as to how this should be done? If I comment
> out the
> 'thingTwo' sub_element, it fails with an exception
> indicating that the
> element 'sub_element' has been declared twice, which seems
> to indicate
> it is ignoring the namespace?
>
> Thanks in anticipation of a solution.
>
> Dave Mellors
>
>
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
-----Inline Attachment Follows-----
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|