users@jaxb.java.net

Re: How to get link to Parent Element?

From: Kevin Wooten <kevin_at_wooten.com>
Date: Wed, 2 Jul 2008 09:04:37 -0700

I use XPath to solve this. Which works well since it allows you to
satisfy almost any query you could possibly have. It does require you
to go back and forth between the DOM and the JAXB objects but that is
trivial when using the Binder.

A little psuedo code for your situation..

Node xmlNode = Binder.getXmlNode([JAXBObjectToFindParentOf]);
XPathFactory fac = XPathFactory.newInstance();
XPath xpath = fac.newXPath();
//Set properties on xpath like namespaces used, etc.
Node parentNode = (Node)xpath.evaluate("..", xmlNode,
XPathConstants.NODE);
return Binder.getJAXBNode(parentNode);

Hope this helps!

On Jul 2, 2008, at 8:41 AM, Markus Karg wrote:

> I am a beginner with JAXB and not using schemas at all, only using
> manually annotated classes.
>
> There is the following XML:
>
> <A>
> <B />
> <C />
> </A>
>
> So I wrote classes A, B and C and added @XmlRootElement to both.
>
> But now I want to be able inside of classes B and C to ask for the
> surrounding A.
>
> Is there some "JAXB Magic" that will provide a "Parent Pointer"
> automatically?
> Or what is the best idea to get that pointer (without changing the
> above XML schema)?
>
> Maybe the question is silly, but see, I am a total JAXB beginner. ;-)
>
> Thanks a lot!
> Markus
>
>
> QUIPSY QUALITY GmbH & Co. KG
> Ein Unternehmen der MES-Gruppe
> Stuttgarter Strasse 23
> D-75179 Pforzheim
> Tel: 07231-9189-52
> Fax: 07231-9189-59
> www.quipsy.de
> karg_at_quipsy.de
> Registergericht Mannheim HRA 701214
> Geschäftsführer: Nils Schroeder
>
> Diese E-Mail enthält persönliche, vertrauliche und vor Weitergabe
> geschützte Informationen und ist ausschließlich für den vorgesehenen
> o.g. Empfänger (Adressaten) bestimmt. Falls Sie diese E-Mail
> versehentlich erhalten haben und nicht der vorgesehene Empfänger
> sind, bitten wir Sie, die E-Mail und deren Anhänge nicht
> aufzubewahren, nicht zu vervielfältigen, nicht zu nutzen und nicht
> weiterzugeben. Bitte informieren Sie uns als Absender über diesen
> Zustellungsfehler und löschen Sie die E-Mail.
>
>
>
>
>
> <Markus
> KARG
> .vcf
> >---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net