|
Re: Does XMLBeans expose annotation and appinfo elements?: msg#00101text.xml.xmlbeans.user
Radu, I'll look forward to that! I've been working on something very similar to Jim M. I'm using XML Beans for the data transport layer to a database Web Service. The Web Service takes an XML document and works-out which table needs to be selected/inserted/updated/deleted based on the schema definition for that document. To read an XML document for an update operation, I'm using XML cursors (combined with the information held in the document SchemaType) to navigate to the relevant detail element. For example: <users xmlns="http://mycompany.com/dbws/users" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mycompany.com/dbws/users"> <user> <id>000001</id> <name>Jim H</name> <!-- other fields here --> </user> <!-- other users if required --> </users> ...can be read thus: XmlCursor mXmlCursor = null; public XmlObject firstItem(XmlObject pDocument, SchemaType pItemType) //item type is UserType.type in this example { if (!pDocument.schemaType().isDocumentType()) { throw new IllegalArgumentException("passed object is not a document type" + pDocument.schemaType().getName().getLocalPart()); } mXmlCursor = pDocument.newCursor(); mXmlCursor.toStartDoc(); while (!mXmlCursor.isEnddoc()) { if (mXmlCursor.getObject() != null && mXmlCursor.getObject().schemaType() == pItemType) { return mXmlCursor.getObject(); } mXmlCursor.toNextToken(); } return null; } public XmlObject nextItem() { boolean isMore = mXmlCursor.toNextSibling(); if (isMore) { return mXmlCursor.getObject(); } else { return null; } } ...so reading a Users document is now easy: UserType xmlUser = (UserType)firstItem(pDoc, UserType.type); int i = 0; while (xmlUser != null) { mLogger.debug("nextItem: "+xmlUser); mLogger.debug("userId: "+xmlUser.getUserId()); xmlUser = (UserType)nextItem(); } I'm creating documents using XMLCursor too, something like... XmlObject doc = newDocument(); XmlCursor xc = doc.newCursor(); xc.toNextToken(); SchemaProperty root = getDocumentRoot(); // Users.type in this case xc.beginElement(root.getName()); addAttrs(xc, pAttrs); xc.dispose(); Hope this gives you some ideas... Jim Yes, but only in the upcoming XmlBeansV2. |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: Does XMLBeans expose annotation and appinfo elements?: 00101, Jim McMaster |
|---|---|
| Next by Date: | RE: Does XMLBeans expose annotation and appinfo elements?: 00101, Radu Preotiuc-Pietro |
| Previous by Thread: | RE: Does XMLBeans expose annotation and appinfo elements?i: 00101, Jim McMaster |
| Next by Thread: | RE: Does XMLBeans expose annotation and appinfo elements?: 00101, Radu Preotiuc-Pietro |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |