0

Folks,

I m just wondering how could I remove an xml element by given tag name from given xml using AXIOM xml process library.

so far i have successfully build document.

StAXOMBuilder builder = new StAXOMBuilder(stream);
OMElement documentBuilder = builder.getDocumentElement();

thanks in advance.

Roshan Wijesena
  • 3,106
  • 8
  • 38
  • 57

2 Answers2

1
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(stream);
OMElement documentElement = builder.getDocumentElement();
Iterator it = documentElement.getChildrenWithName(new QName("http://namespace", "elementName"));
if (it.hasNext()) {
    it.next();
    it.remove();
}
Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
  • 1
    This might be the answer to the question, but a little explanation might be for OP good to understand where his problem was and how the solution works! – Rizier123 Dec 06 '14 at 10:34
0

Well, I found the solution

  StAXOMBuilder builder = new StAXOMBuilder(stream);
    OMElement documentBuilder = builder.getDocumentElement();

     Iterator allChildren = documentBuilder.getChildren();
     while (allChildren.hasNext()) {
        OMElement omElement = (OMElement) allChildren.next();
        String elementName = omElement.getQName().toString();

        if ("apimPayload".equals(elementName)) {                       
        omElement.detach();
        break;
        }
     }
Roshan Wijesena
  • 3,106
  • 8
  • 38
  • 57