Hi there, sorry if this is an obvious question, but I’ve been seeing problems unmarshalling DOM nodes into xmlbeans successfully.

 

This is the code I’m using:

 

public static void main(String[] argv)

        throws Exception

    {

        FileInputStream fis = new FileInputStream(argv[0]);

 

        // get a DOM tree from an input file

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

        dbf.setIgnoringComments(false);

        dbf.setIgnoringElementContentWhitespace(false);

        dbf.setNamespaceAware(true);

        dbf.setValidating(false);

        DocumentBuilder db = dbf.newDocumentBuilder();

        Document doc = db.parse(fis);

       

        // isolate an element I wish to xmlbeans-ify - I don't want the whole thing

        Element tasksElement =(Element) doc.getElementsByTagName("Tasks").item(0);

        Element associateElement = (Element) tasksElement.getElementsByTagName("AssociateUserRoleTask").item(0);

       

        // check my DOM attribute is set - this gives a correct value

        System.out.println("From DOM: " + associateElement.getAttribute("displayRoleName"));

 

        // unmarshal to xmlbeans - this succeeds

        AssociateUserRoleTaskType aurt = AssociateUserRoleTaskType.Factory.parse(associateElement);

 

        // but this returns null, where I know the attribute displayRoleName is set!

        XmlAnySimpleType attr = aurt.getDisplayRoleName();

       

        // and even odder - the attribute is correctly set in this dump!!

        System.out.println(aurt.xmlText());

   }

 

I’ve had even worse problems when I try to go back to DOM using XmlTokenSource.newDomNode() as well.  Is trying to isolate, edit, and then return a section of a DOM tree using xmlbeans even something I should expect to be able to do?

 

David Barrett

Computer Associates

eTrust Admin Development, Melbourne, Australia

 

Reply via email to