Hi,

I would expect this question be answered many times or on the XML beans
website, but I can't find the answers.

Essentially, I just try to convert an XmlObject to a DOM Element

    Node node = xmlbean.getDomNode(); // works
    Element elem = (Element) node; // failed

with error java.lang.ClassCastException:
org.apache.xmlbeans.impl.store.Xobj$DocumentFragXobj

And I have to use kludge like

     XmlCursor cursor = xmlbean.newCursor();
     boolean hasAttr = cursor.toFirstAttribute();
     while (hasAttr) {
           final QName attr = cursor.getName();
           if (idAttr.equals(attr.getLocalPart())) {
              value = cursor.getTextValue();
              break;
           }
           hasAttr = cursor.toNextAttribute();
     }

It also seems that cursor methods like toFirstChild() would return an
Element but I do not necessary know the order of the current element in its
parent.

Any idea on a simple and elegant way to get the Element?

Thanks

Reply via email to