|
RE: Does XMLBeans expose annotation and appinfo elements?: msg#00106text.xml.xmlbeans.user
I see. Have you tried XmlCursor.toChild(QName) and XmlCursor.toNextSibling(QName)? They do almost what your firstItem() and nextItem() do, except that they're based on the QName of the element instead of the type. If you don't expect xsi:type to be used, looks like they will behave the same. -----Original Message----- From: Jim Harrison [mailto:iam@xxxxxxxxxxxxxxxx] Sent: Thursday, January 13, 2005 3:17 PM To: user@xxxxxxxxxxxxxxxxxxx Subject: Re: Does XMLBeans expose annotation and appinfo elements? 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. > >Radu > >-----Original Message----- >From: Jim McMaster [mailto:jim.mcmaster@xxxxxxxxxxx] >Sent: Thursday, January 13, 2005 2:30 PM >To: user@xxxxxxxxxxxxxxxxxxx >Subject: Does XMLBeans expose annotation and appinfo elements? > > > >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >I am new to XMLBeans, and cannot find the answer in the documentation >or list archives. I need to generate XML documents for multiple >schemas, and would like to do it in a generic way. In particular, >the values for attributes and content need to be acquired through >method calls. I would like to generate a mapping from the schema >type to a command object that would retrieve values from a database. > >The annotation, and particularly appinfo elements seem to be a place >where I can annotate a type. If I compile a schema with these >elements, will XMLBeans expose them through the generated classes, or >through the schema type interface? > >Thank you for any help. > >- -- >Jim McMaster >mailto:jim.mcmaster@xxxxxxxxxxx > > >-----BEGIN PGP SIGNATURE----- >Version: PGP 8.1 > >iQA/AwUBQeb2V2aP5l7/atSJEQK0LgCgrQ5rKMYARFIiNYRBgMnruSgAhyoAn2oE >CNGW+Hdyj1zWDive8o/hft/o >=ShM+ >-----END PGP SIGNATURE----- > > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx >For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx >For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: German Umlauts and other special characters: 00106, Simmie, Anne Marie |
|---|---|
| Next by Date: | RE: German Umlauts and other special characters: 00106, Cordes, Hans-Dieter |
| Previous by Thread: | RE: Does XMLBeans expose annotation and appinfo elements?i: 00106, Radu Preotiuc-Pietro |
| Next by Thread: | FW: Map specific names to enum classes: 00106, Simmie, Anne Marie |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |