Skip to Content
author's profile photo Former Member
Former Member

Removing Tag from XML

Hi...

I have this XML:

<CONTROLE>

<item>

<FUNCAO>123456</FUNCAO>

<CNPJANCORA>1234123412341234</CNPJANCORA>

<TEMPOSISINT />

<TEMPOSISINTMIDDLE />

</item>

</CONTROLE>

<GANHADOR>

<item>

<COLLECTIVENUMBER>23523525</COLLECTIVENUMBER>

<CODIGOITEM>234234234</CODIGOITEM>

<CODIGOSAP>23423423423</CODIGOSAP>

<CODIGORODADA />

</item>

</GANHADOR>

<RETURN />

I need to know, how to remove the "item" tag from this XML.

I'm trying this:

NodeList controleWS = docOut.getElementsByTagName("Controle");

Text funcao = docOut.createTextNode(controleRFC.item(0).getFirstChild().getNodeValue());

Text cnpj = docOut.createTextNode(controleRFC.item(0).getFirstChild().getNodeValue());

controleWS.item(0).getChildNodes().item(0).appendChild(funcao);

controleWS.item(0).getChildNodes().item(1).appendChild(cnpj);

try{

NodeList ndGanhadorIn = docIn.getElementsByTagName("GANHADOR");

NodeList ndGanhadorOut = docOut.getElementsByTagName("Ganhador");

/*Text txtColNumber = docOut.createTextNode(ndGanhadorIn.item(0).getFirstChild().getNodeValue());

Text txtCodItem = docOut.createTextNode(ndGanhadorIn.item(0).getFirstChild().getNodeValue());

Text txtCodSAP = docOut.createTextNode(ndGanhadorIn.item(0).getFirstChild().getNodeValue());

Text txtCodRodada = docOut.createTextNode(ndGanhadorIn.item(0).getFirstChild().getNodeValue());*/

Text txtColNumber = docOut.createTextNode("0");

Text txtCodItem = docOut.createTextNode("1");

Text txtCodSAP = docOut.createTextNode("2");

Text txtCodRodada = docOut.createTextNode("3");

ndGanhadorOut.item(0).getChildNodes().item(0).appendChild(txtColNumber);

ndGanhadorOut.item(0).getChildNodes().item(1).appendChild(txtCodItem);

ndGanhadorOut.item(0).getChildNodes().item(2).appendChild(txtCodSAP);

ndGanhadorOut.item(0).getChildNodes().item(3).appendChild(txtCodRodada);

}catch(Exception e){

System.out.println("Ganhador -> " + e);

}

It works with Controle tag, but doesn't work with Ganhador.

What can I do?

Thanx!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jan 16, 2009 at 12:12 PM

    >

    > Hi...

    >

    > I have this XML:

    > <CONTROLE>

    > <item>

    > <FUNCAO>123456</FUNCAO>

    > <CNPJANCORA>1234123412341234</CNPJANCORA>

    > <TEMPOSISINT />

    > <TEMPOSISINTMIDDLE />

    > </item>

    > </CONTROLE>

    > <GANHADOR>

    > <item>

    > <COLLECTIVENUMBER>23523525</COLLECTIVENUMBER>

    > <CODIGOITEM>234234234</CODIGOITEM>

    > <CODIGOSAP>23423423423</CODIGOSAP>

    > <CODIGORODADA />

    > </item>

    > </GANHADOR>

    > <RETURN />

    >

    > I need to know, how to remove the "item" tag from this XML.

    i would suggest a simple replaceAll java function.

    stringpayload.replaceAll("<item>","");
    stringpayload.replaceAll("</item>","");

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.