Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Unmarshall Generated xml.

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Below is an example schema and xml content generated from eclipse ( select xsd -> generate xml )

Car.xsd file


Car.Xml file



I have 3 questions


1) I would expect the "name" and "EngineSize" elements to be prefixed with "p:" similar to Cartype as all the elements
are defined in the same targetname space.

Why is this not the case ?

2) I am not able to unmarshall the above xml as shown, but if I prefix the "name" and EngineSize elements with "p:",
I am than able to unmarshall the xml.
Is it possible to unmarshall the xml without making this change ?

3) How is the prefix "p" derived ?
Can this be specified.


Thank you for your help.

Pete
 
Sheriff
Posts: 26798
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to me that you have questions about namespaces in general, and then specific questions about why Eclipse did what it did when you asked it to do something. So as for the namespace questions, it would probably help if you read this introduction to XML namespaces:

http://www.xml.com/pub/a/1999/01/namespaces.html

As for the Eclipse questions... perhaps they'll be answered by that article. If not, then by all means post revised questions after you've read it.
 
Pete Palmer
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi Paul

I read through the article. It is a nice introduction to namespaces.

However, it didn;t answer any of my questions - primarily because the subject of my questions are out of scope for the article.

I mentioned how I used Eclipse for information but my questions are specific to the subject of namespace.

Still thank you for pointing me to the article,

Regards
Pete.
 
Paul Clapham
Sheriff
Posts: 26798
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought it answered #3 when it said that namespace prefixes are meaningless. As for the others, yeah... but my badly-made point was that you didn't say anything about what you did in Eclipse.

However, since you're mainly concerned about how that Eclipse feature works (or fails to work) let me move this thread to the IDE forum where questions about Eclipse belong. Perhaps you could fill in some details about what you did in Eclipse to generate that XML?
 
Ranch Hand
Posts: 733
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1:

1) I would expect the "name" and "EngineSize" elements to be prefixed with "p:" similar to Cartype as all the elements
are defined in the same targetname space.
Why is this not the case ?


A1:
The expectation is wrong. The utility has generated a proper document and has read the schema properly.
If you want to have "name" and "EngineSize" to live in the same namespace as that of CarType, you have to add the attribute elementFormDefault qualified to the schema.

The default value is "unqualified" meaning local scope elements do not belong to any namespace (or belong to null/empty namesapce).

Q2:

2) I am not able to unmarshall the above xml as shown, but if I prefix the "name" and EngineSize elements with "p:",
I am than able to unmarshall the xml.
Is it possible to unmarshall the xml without making this change ?


A2:
You can use schema compiler to generate a typical setup of the object graph. In particular, you may be interested to note that the schema binding for the elementFormDefault being qualified is reflected in the package-info.java. And that the local scope elements are generated as inner classes rather than classes sitting in the package directory as such.
The point is also that you may be able to parse the setup of pojo you're actually running with (that we don't have any idea what it is, but I may devine somehow what it probably looks like), but that you won't be able to validate with the schema "as such" with out addition I mentioned --- that I am sure.

Q3:

3) How is the prefix "p" derived ?
Can this be specified.


A3:
This is the only question not properly concerned with jaxb. It concerns with the specific application/plugin extension. As the specific prefix being use is not a generic xml qualifiable behaviour, you've to pose the question to the plugin documentation. It may be or it may not be customized according to the user's, but the interest is not primal, far from it.
 
Pete Palmer
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks g tsuji for the responses.

Ok much clearly on some of my issues.

Unfortunately, the xsd is fixed and too late to intrroduce the elementFormDefault="quaified".

Any chance of sample example of how I can perform your suggestion to your answer to Q2 please.


Many thanks for your help.

Pete
 
g tsuji
Ranch Hand
Posts: 733
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just mainly want to highlight that I have made a typo during the writeup: it is "qualified" with an "l" --- seems to me obvious!

As to the example, I have already pointed you out the way how to set up, actually more than just being an example, but a working full setup.
 
Pete Palmer
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi g tsuji,

You can use schema compiler to generate a typical setup of the object graph.

Would you be able to elaborate a bit more as I am not clear on this.

In particular, you may be interested to note that the schema binding for the elementFormDefault being qualified is reflected in the package-info.java. And that the local scope elements are generated as inner classes rather than classes sitting in the package directory as such.

Checked this and it is as you have said.
package-info.java has
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED.

The point is also that you may be able to parse the setup of pojo you're actually running with (that we don't have any idea what it is, but I may devine somehow what it probably looks like), but that you won't be able to validate with the schema "as such" with out addition I mentioned


The addition you ref to is that I need to add "elementFormDefault="qualified"" to the xsd. Only with this change will be able to unmarshall. Is this correct ?

Below is what my approach to unmarshall the xml sting for Car.xsd.





 
g tsuji
Ranch Hand
Posts: 733
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

package-info.java has
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED.


If you have the intention to use the displayed schema as such, fixed and in no position to alter, which is absolutely a admissible schema of its own, why should that qualifier appeared in the package-jave? Simply take that out. That action means you don't have to alter an iota of the schema---that answer your another question too: it will be able to unmarshall under the condition obviously that the rest is properly coded! (To mention in passing, why the class be named Car instead of CarType? But I won't insist upon it as you are fully entitled to withhold info privy to you, only I would suggest you should make a coherent story rather than incoherent.)
 
Pete Palmer
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The package-info.java has elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED. as it is inserted by the wsdl2java process. The xsd is used by the web service wsdl.

Appologises for the incoherent story - introduced in the process of trying to use dummy examples instead the actual


Probably one last question which touches on a point made.

The xsd will be used to send and received information with a server - effectively marshall and unmarshall - the request and response respectively.

The namespace prefix on the message need to be fix ie instead "p" it has to be "fred". ie the parent element has a prefix "fred" and child element have nothing.



I have modified the package-info.java file as follows :-




With the above package-info change, request messages going OUT to the server are going out in the correct format ie has a prefix of "fred".

I am able to unmarshall messages from the server which are in the format as above. All good.

However, I am ALSO able to unmarshall messages from the server which are in the format as above BUT the prefix can set to 'sunday', and still able to unmarshall successfully.

I thought the line
@javax.xml.bind.annotation.XmlNs(prefix = "fred", namespaceURI ="http://www.my.car.com")
said the parent element must have a prefix of "fred" but seems can be anything as long as there is a prefix.

So what does the line
@javax.xml.bind.annotation.XmlNs(prefix = "fred", namespaceURI ="http://www.my.car.com")
actually mean ?


Thank you again.

Pete

 
g tsuji
Ranch Hand
Posts: 733
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That can only be considered as a sweetener for an otherwise completely implementation-dependent prefix generation rule. It affects only Marshaller for the outgoing serialized xml document. It has no effect on the Unmarshaller operation, naturally, otherwise it would break and not be complying with namespace recommendation.

When Marshller streams to some writer, if it encounters some namespace() uri, a generic info, match the xmlns[] there, it would use the prefix specified there. However, if it encounters some namespace() without any match in the xmlns[] there, the prefix would still be generated but of implementation-dependent way out of the control of the authorship of the application using it. Furthermore, if some entries in the xmlns[] there have found no use at all, it would all the same generate those "un-used" entries as per what the author is desired to have and will not discard them overriding what the author is trying to instruct what the engine should do.

That's the systematic of it.
 
Pete Palmer
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi g tsuji

That is a great comprehensive answer.

I think that brings to close a very interesting and informative discussion.

Again thank you for all your help.

Pete
 
Pete Palmer
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi g tsuji

That is a great comprehensive answer.

I think that brings to a close very interesting and informative discussion.

Again thank you for all your help.

Pete
 
It means our mission is in jeapordy! Quick, read this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic