xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arek Stryjski <develo...@krzyzowki.net.pl>
Subject newDomNode(XmlOptions) (was: binding XML fragment from DOM Node)
Date Thu, 29 Jul 2004 12:39:38 GMT
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:4514)
 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.java:154)
 at org.apache.xmlbeans.impl.values.XmlObjectBase.newDomNode(XmlObjectBase.java: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/


Mime
View raw message