Thursday, April 21, 2011

Adding namespace definition to xml using apache xmlbeans

I need to add namespace defintion to an element since its not getting added when when xml is generated using apache xmlbean. How do I acheieve this using xmlbeans API?

From stackoverflow
  • I have found answer to the problem. Here's how it is.

    XmlCursor cursor= targetObject.newCursor();
    cursor.toNextToken();
    cursor.insertNamespace("A", "namespace1");
    //For exmaple
    cursor.insertNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    cursor.dispose();
    

0 comments:

Post a Comment