users@jaxb.java.net

Re: Re: Accessing JAXB mappings

From: <santony_at_bellsouth.net>
Date: Sat, 28 Aug 2004 1:01:53 -0400

> Though I cannot remember the exact syntax, I remember getting the Dom node from the jaxb object.
>
This is what I was alluding to earlier



//create a marshaller
JAXBContext jc = JAXBContext.newInstance( "com.acme.foo" );
Marshaller m = jc.createMarshaller();



//create a new document
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();

//obj is the jaxb object
m.marshal( obj, doc );


Node nod = doc.getDocumentElement() ;


//apply the xpath on the node
Document doc = nod.getOwnerDocument() ;
XPathEvaluator evaluator = new XPathEvaluatorImpl( document ) ;
Element nsRoot = document.getDocumentElement() ;
XPathNSResolver resolver = evaluator.createNSResolver( nsRoot ) ;

XPathResult result = (XPathResult)evaluator.evaluate( "normalize-space(" + xpath + ")", document, resolver, XPathResult.STRING_TYPE, null ) ;

Note that all APIs used are standardized and portable.

--sony


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net