users@jaxb.java.net

Re: While parsing with JAXB, sub branch is coming null

From: olamalam <ilker.cikrikcili_at_aspone.co.uk>
Date: Tue, 9 Nov 2010 09:59:33 -0800 (PST)

Hi Wolfgang,

Yes creating 4 different xsd files solved the problem. And yes again, xjc
created classes in an awful structure. But I'll prefer this solution, thanks
a lot.

ilker


Wolfgang Laun-2 wrote:
>
> Stripping /xmlns="[^"]*"/ from the received XML text may be the simplest
> option :-)
>
> But here's what you might do to use schema and XML as they are:
>
> Decompose the XML schema. The top level schema contains the definition for
> element "iq", and it imports another schema from, say, "commands.xsd".
> Note
> the definition of prefix q1.
>
> <?xml version="1.0" encoding="utf-8"?>
> <xs:schema attributeFormDefault="unqualified"
> elementFormDefault="qualified"
>
> xmlns:q1="http://jabber.org/protocol/commands"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <xs:import namespace="http://jabber.org/protocol/commands"
> schemaLocation="commands.xsd"/>
> <xs:element name="iq">
> <xs:complexType>
> <xs:sequence>
> <xs:element minOccurs="0" ref="q1:command" />
> </xs:sequence>
> <xs:attribute name="id" ...
>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
> Next, "commands.xsd" has a similar structure, importing namespace
> "urn:xmpp:tmp:io-data" from "iodata.xsd".
>
> And so on, until you have 4 xsd files.
>
> xjc the top-level getProfile.xsd; all others are pulled in automatically.
>
> After you Java-compile everything, you'll see that the generated classes
> are
> rather loathsome; expect one level of inner class nesting for each nested
> XML element with an inline type, e.g., Profiles.Profile.Actions.Action.
>
> Manually giving names to some schema types might help.
>
> -W
>
>
> On 9 November 2010 11:00, olamalam <ilker.cikrikcili_at_aspone.co.uk> wrote:
>
>>
>> Hello Wolfgang,
>> Thanks for your reply.
>>
>> I'm developing an integration system and the xml file is what we receive
>> from our client. Yes, when I remove xmlns=",,,commands" manually,
>> commands
>> object is started to be filled however the inner object (iodata) is
>> coming
>> null now. So I guess I need to remove all xmlns fields whenever I receive
>> a
>> message from client programmatically but it is not a very pleasant
>> solution.
>>
>> I generated the xsd file by liquid xml studio. When I use some other
>> tools,
>> xmlns:q1="..." fields aren't created. However I'm having the same problem
>> even if I'm using the new xsd file, command is coming null. The new xsd
>> file
>> is attached. In xmlbeans forum they suggested me to set targetnamespace
>> to
>> the xsd file. But when I set a targetnamespace manually, I' getting
>> validation errors.
>>
>> Do you thing that entering targetnamespace also solves the problem? What
>> should I set there?
>>
>> Thanks again
>> ilker
>>
>>
>> Wolfgang Laun-2 wrote:
>> >
>> > Please remove the xmlns=",,,commands" from the <command> element and
>> try
>> > unmarshalling. If I haven't missed something, this will bring the
>> element
>> > into the correct (according to the XML schema) namespace.
>> >
>> > In the schema, there is indeed
>> > xmlns:q1="http://jabber.org/protocol/commands",
>> > but the prefix q1 isn't used anywhere, so this is just dead freight.
>> >
>> > -W
>> >
>> >
>> > <command xmlns="http://jabber.org/protocol/commands"
>> >
>> >
>> > On 8 November 2010 17:31, olamalam <ilker.cikrikcili_at_aspone.co.uk>
>> wrote:
>> >
>> >>
>> >> Hi to all,
>> >>
>> >> Actually, I'm not new to JAXB :) however I've faced with a problem for
>> >> the
>> >> first time and couldn't solve it.
>> >>
>> >> I"m using Java 1.6.0_18 and the xml file I'm trying to parse and it's
>> >> schema
>> >> are attached. I created the class files by using "xjc" command
>> properly
>> >> but
>> >> when I parse the file, the first tag is returned with correct values
>> at
>> >> "id", "to", "from" and "type" fields but "command" object returns
>> null.
>> I
>> >> also tried parsing it with xmlBeans but I got the same problem there
>> too.
>> >> (I'm going to ask the same question to xmlBeans forum)
>> >>
>> >> Can you see what I'm missing?
>> >>
>> >> http://old.nabble.com/file/p30162263/getProfile.xml getProfile.xml
>> >> http://old.nabble.com/file/p30162263/getProfile.xsd getProfile.xsd
>> >> --
>> >> View this message in context:
>> >>
>> http://old.nabble.com/While-parsing-with-JAXB%2C-sub-branch-is-coming-null-tp30162263p30162263.html
>> >> Sent from the java.net - jaxb users mailing list archive at
>> Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> >> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>> >>
>> >>
>> >
>> >
>> http://old.nabble.com/file/p30169307/getprofile.xsd getprofile.xsd
>> --
>> View this message in context:
>> http://old.nabble.com/While-parsing-with-JAXB%2C-sub-branch-is-coming-null-tp30162263p30169307.html
>> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>>
>>
>
>

-- 
View this message in context: http://old.nabble.com/While-parsing-with-JAXB%2C-sub-branch-is-coming-null-tp30162263p30173449.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.