xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Vasilik" <eric...@bea.com>
Subject RE: newDomNode(XmlOptions) (was: binding XML fragment from DOM Node)
Date Thu, 29 Jul 2004 19:38:56 GMT
DOM is a well known standard, and I have implemented it in the new store
in v2.

When you replace lines 5-7 with that which creates a new instance and
then gets the DOM node, the reason that you get an empty fragment is
that the instance you created is empty.

The expectation you have which is not being met is the initial
construction of an XmlBean creating an element.  

When a new XmlBean instance is created, all you effectively get is an
empty document fragment.  Only after you start adding content, do
elements and attrs start to get created.

I think the exception you are seeing has been fixed in v2, I'll look
into fixing it in v1.

- Eric

> -----Original Message-----
> From: Arek Stryjski [mailto:developer@krzyzowki.net.pl]
> Sent: Thursday, July 29, 2004 5:40 AM
> To: xmlbeans-user@xml.apache.org
> Subject: newDomNode(XmlOptions) (was: binding XML fragment from DOM
Node)
> 
> Hi,
> 
> Sorry if I put too much frustration in my last letter. I still think
> XmlBeans is
> the best binding framework. If you think that using DOM is stupid, I
> agree, but
> unfortunately I need to combine DOM and XmlBeans in my project, as
other
> packages use DOM.
> 
> I read documentation for
org.apache.xmlbeans.XmlTokenSource.newDomNode()
> and now
> I understand that you use only Document and DocumentFragment, but as
you
> need
> one return type you must use Node. The same principle is used in
> parse(Node)
> method I believe.
> I still think there should be some assertion error thrown if I pass
> Element to
> this method, but... it is not something you will call bug.
> 
> However now I come across other behavior which is strange for me.
> Then I use code like this:
> 1  XmlOptions op = new XmlOptions();
> 2  op.setSaveAggresiveNamespaces();
> 3  op.setSaveOuter();
> 4
> 5  SimpleTableModelDocument doc =
> impleTableModelDocument.Factory.newInstance();
> 6  SimpleTableModelBean bean = doc.addNewSimpleTableModel();
> 7  Node n = bean.newDomNode(op);
> 8
> 9  System.out.println("bean="+bean.xmlText());
> 10 System.out.println("node="+n.getFirstChild());
> 
> the system output as expected is:
>    bean=<xml-fragment/>
>    node=<sim:simple-table-model
xmlns:sim="http://xmlbeans/table/simple"
> />
> 
> But if I replace lines 5-7 with:
>    SimpleTableModelBean bean =
SimpleTableModelBean.Factory.newInstance();
>    Node n = bean.newDomNode(op);
> 
> I get in output:
>    bean=<xml-fragment></xml-fragment>
>    node=null
> 
> I looks like now DocumentFragment is empty. But why? It should contain
one
> element in my opinion. Or I'm wrong again?
> 
> The most inexplicable behavior I got then on line 7 I place:
>    Node n = bean.newDomNode();
> 
> it case:
> Exception in thread "main" java.lang.NullPointerException
>  at
>
org.apache.xmlbeans.impl.store.Saver$DomSaver.emitContainer(Saver.java:4
51
> 4)
>  at
org.apache.xmlbeans.impl.store.Saver.processContainer(Saver.java:775)
>  at org.apache.xmlbeans.impl.store.Saver.process(Saver.java:518)
>  at
>
org.apache.xmlbeans.impl.store.Saver$DomSaver.exportDom(Saver.java:4461)
>  at org.apache.xmlbeans.impl.store.Cursor.newDomNode(Cursor.java:2954)
>  at
>
org.apache.xmlbeans.impl.values.XmlObjectBase.newDomNode(XmlObjectBase.j
av
> a:154)
>  at
>
org.apache.xmlbeans.impl.values.XmlObjectBase.newDomNode(XmlObjectBase.j
av
> a:151)
> ...
> on this line.
> 
> So it looks like my problems come from wrong settings in XmlOptions
passed
> to
> newDomNode(); There I could read more about usage of XmlOptions in
context
> of
> DOM import/export.
> 
> Thanks for any help.
> 
> Arek
> 
> 
> 
> -
---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Mime
View raw message