Showing posts with label xmlobject. Show all posts
Showing posts with label xmlobject. Show all posts

Thursday, May 13, 2010

XmlObject, changing QName

snippet of code to change the name of an element

    public static XmlObject changeOperation(XmlObject body) {
        System.out.println("JAVACALLOUT " + body.xmlText());
       
        XmlCursor cur = body.newCursor();
        cur.toFirstChild();
        QName oldQName = cur.getName();
        QName newName = new QName(oldQName.getNamespaceURI(), "newOperation", oldQName.getPrefix());
        cur.setName(newName);
        return body;
    }


this is the input:

JAVACALLOUT <dbac:insertCompany xmlns:dbac="http://com/acme/dbaccess">
  <dbac:company xmlns:java="java:com.acme.dbaccess">
    <java:CreationDate>3</java:CreationDate>
    <java:Id>10</java:Id>
    <java:Name>string</java:Name>
  </dbac:company>
</dbac:insertCompany>

this is the output


AFTER <dbac:newOperation xmlns:dbac="http://com/acme/dbaccess">
  <dbac:company xmlns:java="java:com.acme.dbaccess">
    <java:CreationDate>3</java:CreationDate>
    <java:Id>10</java:Id>
    <java:Name>string</java:Name>
  </dbac:company>
</dbac:newOperation>