on 01-16-2009 11:43 AM
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!
>
> 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>","");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No need to parse the XML as a document.
Your input is already an inputStream, so...
StringBuffer sb = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = in.read(b)) != -1;) {
sb.append(new String(b, 0, n));
}
String str = sb.toString();
That is, if your inputStream may be big enough to justify a buffer (it's always a good approach to use buffers).
If you don't want to, just use this.
byte[] b = new byte[in.available()];
in.read(b);
String str = new String(b);
Alternativelly, in PI 7.1 (Java 1.5), you could use the StringBuilder() class.
After you're done, just write it back to the outputStream.
out.write(str.getBytes());
You can also evaluate using the charSet defined version of the getBytes() method and the String() constructor.
String str = new String(b, "UTF-8");
...
out.write(str.getBytes("UTF-8"));
Regards,
Henrique.
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.