RE: Can I get a SchemType from an XPath without a document instance?
Anthony, You'll need to navigate the SchemaTypeSystem yourself. XMLBeans doesn't include such an utility a this moment. Also, if you know the document class, there is a static field an all the generated interfaces called type that points to its corresponding SchemaType, you can use that one as the stating point of the path navigation. Cezar From: Anthony Fryer [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 26, 2008 6:42 PM To: dev@xmlbeans.apache.org Subject: Can I get a SchemType from an XPath without a document instance? Given a schema document and the xpath of an element in a 'not yet created' xml document that is an instance of the schema, can i get the corresponding schema type of that element somehow? I know that if the XmlObject already exists, I can just find the XmlObject using selectPath and then get the schemaType from the XmlObject, but what can i do if the XmlObject doesn't exist and I only have an xpath? Is this possible? Regards, Anthony Date: Fri, 22 Aug 2008 12:10:44 -0700 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: [jira] Commented: (XMLBEANS-100) Support of DOM Level 3 [ https://issues.apache.org/jira/browse/XMLBEANS-100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=12624957#action_12624957 ] Robert H. Pollack commented on XMLBEANS-100: What works for me as a workaround is to copy the DOM tree created by XMLBeans into a Document created by the JDK's DocumentBuilder. In other words, suppose we have a Document that has been obtained by something like this: Document doc1 = (Document) myXMLObject.newDomNode(); Create a DocumentBuilder in the usual way and use it to build a new Document: DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc2 = builder.newDocument(); (you'll need exception handlers not shown here). Then import the first Document into the second: Element newRoot = (Element) doc2.importNode (doc1.getDocumentElement(), true); doc2.appendChild (newRoot); Now do your work--transformations or whatever--with doc2, which will be a DOM level 3 Document. As I say, this is working fine for me; the JVM has no problem handling two different DOM implementations, a level 2 implementation from XMLBeans and a level 3 implementation from the JDK. And the JDK's implementation seems to have no trouble importing nodes from XMLBeans' implementation. Admittedly, this would not scale to large trees; I have no workaround to suggest when the tree is so large that copying it is expensive. If, afterward, you need to turn this back into an XmlObject, it should be possible to do this by using XmlObject.Factory.parse (doc2), although I haven't tested this since my application doesn't need it. Support of DOM Level 3 -- Key: XMLBEANS-100 URL: https://issues.apache.org/jira/browse/XMLBEANS-100 Project: XMLBeans Issue Type: New Feature Components: DOM Affects Versions: Version 2 Reporter: Walter Dorninger Assignee: Jacob Danner Priority: Minor Fix For: TBD Support of DOM Level 3 would be a powerful feature. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] to the movies Shout your Messenger buddies http://www.livelife.ninemsn.com.au/compIntro.aspx?compId=4590%20
RE: Can I get a SchemType from an XPath without a document instance?
Cezar, Thanks for replying. I started wondering if what I asked was crazy and had a look at how else I could do this and realized that what I wanted was actually to get the schema type using a restricted xpath that essentially uniquely identifies an element (ie. get the schemaType of /document/element1/childElement2 but don't need to support /document//element2 or /document/child::*/element2 etc.), so it turns out I can navigate through the SchemaTypeSystem because I know the directy child of each type as I work my way along the path. I don't need to do any xpath compilation or anything tricky like that fortunately. It would be an interesting feature though to be able to query for a type using full xpath syntax (ie. SchemaType[] SchemaType.selectPath(String path)). I'm using dynamically compiled schemas via XBeans.compileXsd so don't have access to document classes, but I can iterate through the SchemaTypeSystem and find all the defined SchemaTypes ok. The only minor issue I had was I wanted to pass a handle of a schemaType to a client, but it seems for SchemaTypes created through XBeans.compileXsd, the handle is null. I got around that by casting my SchemaTypeSystem to SchemaTypeSystemImpl and calling the undocumented handleForType method but this doesn't do 2 way mapping (ie. can't get the schemaType from the handle), so I have to maintain my own HashMaps of handles to types. Not sure if this is the way to do it but it is working for me so far. Cheers, Anthony From: [EMAIL PROTECTED] To: dev@xmlbeans.apache.org Subject: RE: Can I get a SchemType from an XPath without a document instance? Date: Wed, 27 Aug 2008 17:14:37 -0500 Anthony, You’ll need to navigate the SchemaTypeSystem yourself. XMLBeans doesn’t include such an utility a this moment. Also, if you know the document class, there is a static field an all the generated interfaces called type that points to its corresponding SchemaType, you can use that one as the stating point of the “path” navigation. Cezar From: Anthony Fryer [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 26, 2008 6:42 PM To: dev@xmlbeans.apache.org Subject: Can I get a SchemType from an XPath without a document instance? Given a schema document and the xpath of an element in a 'not yet created' xml document that is an instance of the schema, can i get the corresponding schema type of that element somehow? I know that if the XmlObject already exists, I can just find the XmlObject using selectPath and then get the schemaType from the XmlObject, but what can i do if the XmlObject doesn't exist and I only have an xpath? Is this possible? Regards, Anthony Date: Fri, 22 Aug 2008 12:10:44 -0700 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: [jira] Commented: (XMLBEANS-100) Support of DOM Level 3 [ https://issues.apache.org/jira/browse/XMLBEANS-100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=12624957#action_12624957 ] Robert H. Pollack commented on XMLBEANS-100: What works for me as a workaround is to copy the DOM tree created by XMLBeans into a Document created by the JDK's DocumentBuilder. In other words, suppose we have a Document that has been obtained by something like this: Document doc1 = (Document) myXMLObject.newDomNode(); Create a DocumentBuilder in the usual way and use it to build a new Document: DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc2 = builder.newDocument(); (you'll need exception handlers not shown here). Then import the first Document into the second: Element newRoot = (Element) doc2.importNode (doc1.getDocumentElement(), true); doc2.appendChild (newRoot); Now do your work--transformations or whatever--with doc2, which will be a DOM level 3 Document. As I say, this is working fine for me; the JVM has no problem handling two different DOM implementations, a level 2 implementation from XMLBeans and a level 3 implementation from the JDK. And the JDK's implementation seems to have no trouble importing nodes from XMLBeans' implementation. Admittedly, this would not scale to large trees; I have no workaround to suggest when the tree is so large that copying it is expensive. If, afterward, you need to turn this back into an XmlObject, it should be possible to do this by using XmlObject.Factory.parse (doc2), although I haven't tested this since my application doesn't need it. Support of DOM Level 3 -- Key: XMLBEANS-100 URL: https://issues.apache.org/jira/browse/XMLBEANS-100 Project: XMLBeans Issue Type: New Feature Components: DOM Affects Versions: Version 2 Reporter: Walter Dorninger Assignee: Jacob Danner Priority: Minor Fix For: TBD Support of DOM Level 3 would be a powerful feature.
RE: Can I get a SchemType from an XPath without a document instance?
Anthony, It's an interesting idea, if anybody does it, let us know and we'll add it in. Indeed you can't use the QName (SchemaType.getName()) since inner definitions don't have names. But for this you should use signatures, to get one just use SchemaType.toString(), and for finding it back SchemaTypeSystem/Loader.typeForSignature(). Cezar From: Anthony Fryer [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 27, 2008 6:01 PM To: dev@xmlbeans.apache.org Subject: RE: Can I get a SchemType from an XPath without a document instance? Cezar, Thanks for replying. I started wondering if what I asked was crazy and had a look at how else I could do this and realized that what I wanted was actually to get the schema type using a restricted xpath that essentially uniquely identifies an element (ie. get the schemaType of /document/element1/childElement2 but don't need to support /document//element2 or /document/child::*/element2 etc.), so it turns out I can navigate through the SchemaTypeSystem because I know the directy child of each type as I work my way along the path. I don't need to do any xpath compilation or anything tricky like that fortunately. It would be an interesting feature though to be able to query for a type using full xpath syntax (ie. SchemaType[] SchemaType.selectPath(String path)). I'm using dynamically compiled schemas via XBeans.compileXsd so don't have access to document classes, but I can iterate through the SchemaTypeSystem and find all the defined SchemaTypes ok. The only minor issue I had was I wanted to pass a handle of a schemaType to a client, but it seems for SchemaTypes created through XBeans.compileXsd, the handle is null. I got around that by casting my SchemaTypeSystem to SchemaTypeSystemImpl and calling the undocumented handleForType method but this doesn't do 2 way mapping (ie. can't get the schemaType from the handle), so I have to maintain my own HashMaps of handles to types. Not sure if this is the way to do it but it is working for me so far. Cheers, Anthony From: [EMAIL PROTECTED] To: dev@xmlbeans.apache.org Subject: RE: Can I get a SchemType from an XPath without a document instance? Date: Wed, 27 Aug 2008 17:14:37 -0500 Anthony, You'll need to navigate the SchemaTypeSystem yourself. XMLBeans doesn't include such an utility a this moment. Also, if you know the document class, there is a static field an all the generated interfaces called type that points to its corresponding SchemaType, you can use that one as the stating point of the path navigation. Cezar From: Anthony Fryer [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 26, 2008 6:42 PM To: dev@xmlbeans.apache.org Subject: Can I get a SchemType from an XPath without a document instance? Given a schema document and the xpath of an element in a 'not yet created' xml document that is an instance of the schema, can i get the corresponding schema type of that element somehow? I know that if the XmlObject already exists, I can just find the XmlObject using selectPath and then get the schemaType from the XmlObject, but what can i do if the XmlObject doesn't exist and I only have an xpath? Is this possible? Regards, Anthony Date: Fri, 22 Aug 2008 12:10:44 -0700 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: [jira] Commented: (XMLBEANS-100) Support of DOM Level 3 [ https://issues.apache.org/jira/browse/XMLBEANS-100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=12624957#action_12624957 ] Robert H. Pollack commented on XMLBEANS-100: What works for me as a workaround is to copy the DOM tree created by XMLBeans into a Document created by the JDK's DocumentBuilder. In other words, suppose we have a Document that has been obtained by something like this: Document doc1 = (Document) myXMLObject.newDomNode(); Create a DocumentBuilder in the usual way and use it to build a new Document: DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc2 = builder.newDocument(); (you'll need exception handlers not shown here). Then import the first Document into the second: Element newRoot = (Element) doc2.importNode (doc1.getDocumentElement(), true); doc2.appendChild (newRoot); Now do your work--transformations or whatever--with doc2, which will be a DOM level 3 Document. As I say, this is working fine for me; the JVM has no problem handling two different DOM implementations, a level 2 implementation from XMLBeans and a level 3 implementation from the JDK. And the JDK's implementation seems to have no trouble importing nodes from XMLBeans' implementation. Admittedly, this would not scale to large trees; I have no workaround to suggest when the tree is so large that