Mapping question - how to remove empty recordsets from output XML?
Hello everyone!
I have a mapping problem I hope you can help me out with.
Here is an example of the source message:
<IDOC>
. <HEAD>
. </HEAD>
. <DET>
. . <Node>
. . . <nodeA>001</nodeA>
. . . <nodeB>OA</nodeB>
. . </Node>
. . <Node>
. . . <nodeB>OB</nodeB>
. . </Node>
. . <Node>
. . . <nodeA>002</nodeA>
. . . <nodeB>OC</nodeB>
. . </Node>
. </DET>
</IDOC>
After testing the above XML in the message mapping, here's what my target looks like:
<FILE>
. . <Rec>
. . . <nA>001</nA>
. . . <nB>OA</nB>
. . </Rec>
. . <Rec>
. . . <nB>
. . . <nA>
. . </Rec>
. . <Rec>
. . . <nA>002</nA>
. . . <nB>OC</nB>
. . </Rec>
</FILE>
"Node" in the "source" message is mapped to "Rec" in my "target" message.
"Node=" -
> "Rec"
You may notice the the "Rec" in the second entry has empty fields. The reason this is so is because I put an "IF" condition in field "nA" and field "nB" that checks whether "nodeA" in the "source" exists/has a value, and if it doesn't, empty values should be given.
Here's my problem, I need the XML output to be clean. All empty Recs should be removed from the Output XML so that it resembles the one below:
<FILE>
. . <Rec>
. . . <nA>001</nA>
. . . <nB>OA</nB>
. . </Rec>
. . <Rec>
. . . <nA>002</nA>
. . . <nB>OC</nB>
. . </Rec>
</FILE>
I've tried several ways to get this done to no avail. Would anyone be able to help me out? I would really, really appreciate it!
Warm regards,
Glenn
Hello,
Here's how the Display Queue looks like from the "CreateIF"
Default Context:
0 [false] [suppress]
1 [false] [suppress]
2 [false] [suppress]
3 [true] []
4 [false] [suppress]
5 [true] []
6 [false] [suppress]
7 [false] [suppress]
8 [false] [suppress]
9 [true] []
10 [false] [suppress]
11 [false] [suppress]
12 [false] [suppress]
13 [true] []
14 [false] [suppress]
15 [false] [suppress]
16 [false] [suppress]
17 [true] []
18 [false] [suppress]
19 [false] [suppress]
20 [false] [suppress]
21 [true] []
CreateIF Context up one notch:
0 [false] [suppress]
1 [true] []
2 [true] []
3 [true] []
4 [true] []
5 [true] []
6 [true] []
7 [true] []
8 [false] [suppress]
9 [false] [suppress]
10 [false] [suppress]
11 [false] [suppress]
Here's how the Display Queue looks like from the "NodeA"
SUPPRESS [false]
SUPPRESS [false]
[0000000292] [false]
[0000000292] [true]
[0000000252] [false]
[0000000252] [true]
SUPPRESS [false]
[0000000078] [false]
[0000000078] [false]
SUPPRESS [true]
[0000000109] [false]
[0000000109] [false]
SUPPRESS [false]
[0000000292] [true]
[0000000292] [false]
SUPPRESS [false]
[0000000076] [false]
[0000000076] [true]
SUPPRESS [false]
[0000000292] [false]
[0000000292] [false]
SUPPRESS [true]
SUPPRESS [false]
NodeA context one notch up:
SUPPRESS [false]
[0000000292] [true]
[0000000252] [true]
[0000000078] [true]
[0000000109] [true]
[0000000292] [true]
[0000000076] [true]
[0000000292] [true]
[0000000074] [true]
[0000000077] [true]
[0000000081] [true]
[0000000292] [true]
[0000000252] [true]
[0000000081] [true]
[0000000081] [false]
SUPPRESS
Hope that helps you help me!
Glenn
Similar Messages
-
How To Remove Empty Node From Source XML
Hi,
How can I remove an empty node from the source xml in a XSLT mapping.
For e.g. If the source xml is like:
<SRC>
<Node1>SAP</Node2>
<Node2/>
<Node3>XI</Node3>
</SRC>
Then the xml should become:
<SRC>
<Node1>SAP</Node2>
<Node3>XI</Node3>
</SRC>
I need to do this because the output of my XSLT mapping is showing blank spaces for each blank node.
Thanks,
Abhishek.Use <xsl:if>
Or else you may find different options here
http://www.dpawson.co.uk/xsl/sect2/N3328.html#d4804e304
Regards,
Prateek -
How to remove duplicates records from output ?
how to remove duplicates records from output ? i used delete adjacent but duplicates records are coming again ..suggest me
hi shruthi,
thanks for ur answer ..but duplicates records coming again
here is my code >> plz check it out
*& Report ZCRM_TROUBLE_TICKET
REPORT zcrm_trouble_ticket.
TYPES : BEGIN OF ty_qmih,
qmnum TYPE qmnum,
equnr TYPE equnr,
iloan TYPE iloan,
ausvn TYPE ausvn,
ausbs TYPE ausbs,
auztv TYPE auztv,
auztb TYPE auztb,
iwerk TYPE iwerk,
END OF ty_qmih,
BEGIN OF ty_qmel,
qmnum TYPE qmnum,
qmtxt TYPE qmtxt,
indtx TYPE indltx,
priok TYPE priok,
strmn TYPE strmn,
strur TYPE strur,
ltrmn TYPE ltrmn,
ltrur TYPE ltrur,
objnr TYPE qmobjnr,
arbpl TYPE lgwid,
vkorg TYPE vkorg,
vtweg TYPE vtweg,
spart TYPE spart,
END OF ty_qmel,
BEGIN OF ty_ihpa,
parnr TYPE i_parnr,
parvw TYPE parvw,
objnr TYPE qmobjnr,
END OF ty_ihpa,
BEGIN OF ty_crhd,
arbpl TYPE arbpl,
objid TYPE cr_objid,
END OF ty_crhd,
BEGIN OF ty_crtx,
ktext TYPE cr_ktext,
objid TYPE cr_objid,
END OF ty_crtx,
BEGIN OF ty_qmfe,
fecod TYPE fecod,
fegrp TYPE fegrp,
qmnum TYPE qmnum,
END OF ty_qmfe,
BEGIN OF ty_qmur,
urcod TYPE urcod,
urgrp TYPE urgrp,
urtxt TYPE urstx,
qmnum TYPE qmnum,
END OF ty_qmur,
BEGIN OF ty_iloa,
tplnr TYPE tplnr,
iloan TYPE iloan,
END OF ty_iloa,
BEGIN OF ty_output,
qmnum TYPE qmnum,
equnr TYPE equnr,
iloan TYPE iloan,
ausvn TYPE ausvn,
ausbs TYPE ausbs,
auztv TYPE auztv,
auztb TYPE auztb,
iwerk TYPE iwerk,
qmtxt TYPE qmtxt,
indtx TYPE indltx,
priok TYPE priok,
strmn TYPE strmn,
strur TYPE strur,
ltrmn TYPE ltrmn,
ltrur TYPE ltrur,
objnr TYPE qmobjnr,
arbpl TYPE lgwid,
vkorg TYPE vkorg,
vtweg TYPE vtweg,
spart TYPE spart,
parnr TYPE i_parnr,
parvw TYPE parvw,
arbpl TYPE arbpl,
objid TYPE cr_objid,
arbpl1 TYPE arbpl,
ktext TYPE cr_ktext,
fecod TYPE fecod,
fegrp TYPE fegrp,
urcod TYPE urcod,
urgrp TYPE urgrp,
urtxt TYPE urstx,
tplnr TYPE tplnr,
END OF ty_output.
DATA : it_qmih TYPE STANDARD TABLE OF ty_qmih,
it_qmel TYPE STANDARD TABLE OF ty_qmel,
it_ihpa TYPE STANDARD TABLE OF ty_ihpa,
it_crhd TYPE STANDARD TABLE OF ty_crhd,
it_crtx TYPE STANDARD TABLE OF ty_crtx,
it_qmfe TYPE STANDARD TABLE OF ty_qmfe,
it_qmur TYPE STANDARD TABLE OF ty_qmur,
it_iloa TYPE STANDARD TABLE OF ty_iloa,
it_output TYPE STANDARD TABLE OF ty_output,
wa_qmih TYPE ty_qmih,
wa_qmel TYPE ty_qmel,
wa_ihpa TYPE ty_ihpa,
wa_crhd TYPE ty_crhd,
wa_crtx TYPE ty_crtx,
wa_qmfe TYPE ty_qmfe,
wa_qmur TYPE ty_qmur,
wa_iloa TYPE ty_iloa,
wa_output TYPE ty_output.
INITIALIZATION.
REFRESH : it_qmih,
it_qmel,
it_ihpa,
it_crhd,
it_crtx,
it_qmfe,
it_qmur,
it_iloa,
it_output.
CLEAR: wa_qmih,
wa_qmel,
wa_ihpa,
wa_crhd,
wa_crtx,
wa_qmfe,
wa_qmur,
wa_iloa,
wa_output.
start-of-selection.
SELECT qmnum
equnr
iloan
ausvn
ausbs
auztv
auztb
iwerk
FROM qmih
INTO TABLE it_qmih.
SORT it_qmih BY qmnum .
DELETE ADJACENT DUPLICATES FROM it_qmih COMPARING qmnum equnr iloan ausvn ausbs auztv auztb iwerk.
SELECT qmnum
qmtxt
indtx
priok
strmn
strur
ltrmn
ltrur
objnr
arbpl
vkorg
vtweg
spart
FROM qmel
INTO TABLE it_qmel
FOR ALL ENTRIES IN it_qmih
WHERE qmnum = it_qmih-qmnum.
SORT it_qmel BY qmnum.
DELETE ADJACENT DUPLICATES FROM it_qmel COMPARING qmnum
qmtxt
indtx
strmn
strur
ltrmn
ltrur
objnr
arbpl
vkorg
vtweg
spart.
IF it_qmel IS NOT INITIAL.
SELECT parnr
parvw
objnr
FROM ihpa
INTO TABLE it_ihpa
FOR ALL ENTRIES IN it_qmel
WHERE objnr = it_qmel-objnr.
ENDIF.
DELETE ADJACENT DUPLICATES FROM it_ihpa COMPARING parnr
parvw
objnr.
IF it_qmel IS NOT INITIAL.
SELECT arbpl
objid
FROM crhd
INTO TABLE it_crhd
FOR ALL ENTRIES IN it_qmel
WHERE objid = it_qmel-arbpl.
ENDIF.
DELETE ADJACENT DUPLICATES FROM it_crhd COMPARING arbpl
objid.
IF it_qmel IS NOT INITIAL.
SELECT ktext
objid
FROM crtx
INTO TABLE it_crtx
FOR ALL ENTRIES IN it_crhd
WHERE objid = it_crhd-objid.
ENDIF.
DELETE ADJACENT DUPLICATES FROM it_crtx COMPARING ktext
objid.
IF it_qmih IS NOT INITIAL.
SELECT fecod
fegrp
qmnum
FROM qmfe
INTO TABLE it_qmfe
FOR ALL ENTRIES IN it_qmih
WHERE qmnum = it_qmih-qmnum.
ENDIF.
SORT it_qmfe BY qmnum.
DELETE ADJACENT DUPLICATES FROM it_qmfe COMPARING fecod
fegrp.
IF it_qmih IS NOT INITIAL.
SELECT urcod
urgrp
urtxt
qmnum
FROM qmur
INTO TABLE it_qmur
FOR ALL ENTRIES IN it_qmih
WHERE qmnum = it_qmih-qmnum.
ENDIF.
SORT it_qmur BY qmnum.
DELETE ADJACENT DUPLICATES FROM it_qmur COMPARING urcod
urgrp
urtxt.
IF it_qmih IS NOT INITIAL.
SELECT tplnr
iloan
FROM iloa
INTO TABLE it_iloa
FOR ALL ENTRIES IN it_qmih
WHERE iloan = it_qmih-iloan.
ENDIF.
DELETE ADJACENT DUPLICATES FROM it_iloa COMPARING tplnr
iloan.
LOOP AT it_qmih INTO wa_qmih.
wa_output-qmnum = wa_qmih-qmnum.
wa_output-equnr = wa_qmih-equnr.
wa_output-iloan = wa_qmih-iloan.
wa_output-ausvn = wa_qmih-ausvn.
wa_output-ausbs = wa_qmih-ausbs.
wa_output-auztv = wa_qmih-auztv.
wa_output-auztb = wa_qmih-auztb.
wa_output-iwerk = wa_qmih-iwerk.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_qmel INTO wa_qmel WITH KEY qmnum = wa_qmih-qmnum.
wa_output-qmtxt = wa_qmel-qmtxt.
wa_output-indtx = wa_qmel-indtx.
wa_output-priok = wa_qmel-priok.
wa_output-strmn = wa_qmel-strmn.
wa_output-strur = wa_qmel-strur.
wa_output-ltrmn = wa_qmel-ltrmn.
wa_output-ltrur = wa_qmel-ltrur.
wa_output-objnr = wa_qmel-objnr.
wa_output-arbpl = wa_qmel-arbpl.
wa_output-vkorg = wa_qmel-vkorg.
wa_output-vtweg = wa_qmel-vtweg.
wa_output-spart = wa_qmel-spart.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_ihpa INTO wa_ihpa WITH KEY objnr = wa_qmel-objnr.
wa_output-parnr = wa_ihpa-parnr.
wa_output-parvw = wa_ihpa-parvw.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_crhd INTO wa_crhd WITH KEY objid = wa_qmel-arbpl.
wa_output-arbpl = wa_crhd-arbpl.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_crtx INTO wa_crtx WITH KEY objid = wa_crhd-objid.
wa_output-ktext = wa_crtx-ktext.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_qmfe INTO wa_qmfe WITH KEY qmnum = wa_qmih-qmnum.
wa_output-fecod = wa_qmfe-fecod.
wa_output-fegrp = wa_qmfe-fegrp.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_qmur INTO wa_qmur WITH KEY qmnum = wa_qmih-qmnum.
wa_output-urcod = wa_qmur-urcod.
wa_output-urgrp = wa_qmur-urgrp.
wa_output-urtxt = wa_qmur-urtxt.
APPEND wa_output TO it_output.
CLEAR wa_output.
READ TABLE it_iloa INTO wa_iloa WITH KEY iloan = wa_qmih-iloan.
wa_output-tplnr = wa_iloa-tplnr.
APPEND wa_output TO it_output.
CLEAR wa_output.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM it_output COMPARING qmnum
equnr
ausvn
ausbs
auztv
auztb
iwerk
qmtxt
indtx
priok
strmn
strur
ltrmn
ltrur
vkorg
vtweg
spart
parnr
parvw
arbpl
ktext
fecod
fegrp
urcod
urgrp
urtxt
tplnr.
*CALL FUNCTION 'STATUS_TEXT_EDIT'
EXPORTING
CLIENT = SY-MANDT
FLG_USER_STAT = ' '
objnr =
ONLY_ACTIVE = 'X'
spras = en
BYPASS_BUFFER = ' '
IMPORTING
ANW_STAT_EXISTING =
E_STSMA =
LINE =
USER_LINE =
STONR =
EXCEPTIONS
OBJECT_NOT_FOUND = 1
OTHERS = 2
*IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
*CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
id =
language =
name =
object =
ARCHIVE_HANDLE = 0
LOCAL_CAT = ' '
IMPORTING
HEADER =
tables
lines =
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8
*IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
*LOOP AT IT_OUTPUT INTO WA_OUTPUT.
*WRITE : / WA_OUTPUT-qmnum,
WA_OUTPUT-equnr,
WA_OUTPUT-iloan,
WA_OUTPUT-ausvn,
WA_OUTPUT-ausbs,
WA_OUTPUT-auztv,
WA_OUTPUT-auztb,
WA_OUTPUT-qmtxt,
WA_OUTPUT-indtx,
WA_OUTPUT-strmn,
WA_OUTPUT-strur,
WA_OUTPUT-ltrmn,
WA_OUTPUT-ltrur,
WA_OUTPUT-objnr,
WA_OUTPUT-arbpl,
WA_OUTPUT-parnr,
WA_OUTPUT-parvw,
WA_OUTPUT-objid,
WA_OUTPUT-ktext,
WA_OUTPUT-fecod,
WA_OUTPUT-fegrp,
WA_OUTPUT-urcod,
WA_OUTPUT-urgrp,
WA_OUTPUT-urtxt,
WA_OUTPUT-tplnr.
*ENDLOOP.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = 'E:\CRM1.TXT'
FILETYPE = 'ASC'
APPEND = ' '
write_field_separator = '|'
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
IMPORTING
FILELENGTH =
TABLES
data_tab = it_output
FIELDNAMES =
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. -
How to remove empty lines from xml files after removing nodes from document
<pre>
Hi
<b>i have xml document, which is shown below
after removing some nodes from the document ,i am getting empty lines in place of removed nodes,how to resolve this and get the proper xml document without any errors</b>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE Message SYSTEM "TRD01.dtd">
<Message>
<Header>
<CounterPartyType>CLIENT</CounterPartyType>
<CreationTime>20134455</CreationTime>
<ErrorCode>363 </ErrorCode>
<ErrorEnterPriseId>N</ErrorEnterPriseId>
<ErrorStatus>1</ErrorStatus>
<ErrorSystemId>STL</ErrorSystemId>
<ErrorTimes>31</ErrorTimes>
<MessageType>T</MessageType>
<RecipientEnterpriseId>N</RecipientEnterpriseId>
<RecipentSystemId>EXM</RecipentSystemId>
<Remarks>REMARSK</Remarks>
<SenderEnterpriseId>N</SenderEnterpriseId>
<SenderSystemId>TR</SenderSystemId>
</Header>
</Message>
<ErrorCode>363 </ErrorCode>
<ErrorEnterPriseId>NIHK</ErrorEnterPriseId>
<ErrorStatus>1</ErrorStatus>
<ErrorSystemId>STL</ErrorSystemId>
<ErrorTimes>31</ErrorTimes>
XPathExpression expression5 = xpath.compile(xmlpath5);
Object result5 = expression5.evaluate(doc, XPathConstants.NODE);
Node node5 = (Node) result5;
node5.getParentNode().removeChild(node5);
XPathExpression expression6 = xpath.compile(xmlpath6);
Object result6 = expression6.evaluate(doc, XPathConstants.NODE);
Node node6=(Node) result6;
node6.getParentNode().removeChild(node6);
XPathExpression expression7 = xpath.compile(xmlpath7);
Object result7 = expression7.evaluate(doc, XPathConstants.NODE);
Node node7=(Node) result7;
node7.getParentNode().removeChild(node7);
doc.normalize();
doc.normalizeDocument();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
t.setOutputProperty(OutputKeys.METHOD,"xml");
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
the xml output i am getting is
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Message>
<Header>
<CounterPartyType>CLIENT</CounterPartyType>
<CreationTime>20134455</CreationTime>
<MessageType>TRD01</MessageType>
<RecipientEnterpriseId>N</RecipientEnterpriseId>
<RecipentSystemId>STL</RecipentSystemId>
<Remarks>REMARSK</Remarks>
<SenderEnterpriseId>N</SenderEnterpriseId>
<SenderSystemId>T</SenderSystemId>
</Header>
</Message>
<b>could you please let me know how to avoid empty lines in the xml doucment output</b>
this is the method i am using to get the result
public void ValidateRecord(String xml){
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
//parse file into DOM
/*DOMParser parser = new DOMParser();
parser.setErrorStream(System.err);
parser.setValidationMode(DTD_validation);
parser.showWarnings(true);*/
System.out.println ("HI THIS xml is validation "+xml);
Resolver res = new Resolver();
db.setEntityResolver(res);
Document doc = db.parse(new InputSource(new StringReader(xml)));
XPathFactory xpf = XPathFactory.newInstance();
XPath xpath = xpf.newXPath();
// XPathExpression expression = xpath.compile("//A/B[C/E/text()=13]");
String xmlpath="/Message/Header/CounterPartyType/text()";
String xmlpath1="/Message/Header/RecipentSystemId/text()";
String xmlpath2="/Message/Header/ErrorSystemId/text()";
XPathExpression expression = xpath.compile(xmlpath);
XPathExpression expression1 = xpath.compile(xmlpath2);
Object result = expression.evaluate(doc, XPathConstants.NODE);
Object result1 = expression1.evaluate(doc, XPathConstants.NODE);
Node node = (Node) result;
Node node1 = (Node) result1;
System.out.println("the values of the string is " +node.getNodeValue());
System.out.println("the values of the string is " +node1.getNodeValue());
// for (int i = 0; i < nodes.getLength(); i++) {
//System.out.println(nodes.item(i).getNodeValue());
// CAHNGING THE RECEIPENT NODE
XPathExpression expression2 = xpath.compile(xmlpath1);
Object result2 = expression2.evaluate(doc, XPathConstants.NODE);
Node node2 = (Node) result2;
System.out.println(node2);
node2.setNodeValue(node1.getNodeValue());
System.out.println(node2);
//removing the nodes from document
String xmlpath3="/Message/Header/ErrorCode";
String xmlpath4="/Message/Header/ErrorEnterPriseId";
String xmlpath5="/Message/Header/ErrorStatus";
String xmlpath6="/Message/Header/ErrorSystemId";
String xmlpath7="/Message/Header/ErrorTimes";
XPathExpression expression3 = xpath.compile(xmlpath3);
Object result3 = expression3.evaluate(doc, XPathConstants.NODE);
Node node3 = (Node) result3;
node3.getParentNode().removeChild(node3);
XPathExpression expression4 = xpath.compile(xmlpath4);
Object result4 = expression4.evaluate(doc, XPathConstants.NODE);
Node node4 = (Node) result4;
System.out.println("node value");
System.out.println(node4.getParentNode().getNodeName());
node4.getParentNode().removeChild(node4);
XPathExpression expression5 = xpath.compile(xmlpath5);
Object result5 = expression5.evaluate(doc, XPathConstants.NODE);
Node node5 = (Node) result5;
node5.getParentNode().removeChild(node5);
XPathExpression expression6 = xpath.compile(xmlpath6);
Object result6 = expression6.evaluate(doc, XPathConstants.NODE);
Node node6=(Node) result6;
node6.getParentNode().removeChild(node6);
XPathExpression expression7 = xpath.compile(xmlpath7);
Object result7 = expression7.evaluate(doc, XPathConstants.NODE);
Node node7=(Node) result7;
node7.getParentNode().removeChild(node7);
// Node b13Node = (Node) expression.evaluate(doc, XPathConstants.NODE);
//b13Node.getParentNode().removeChild(b13Node);
doc.normalize();
doc.normalizeDocument();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
t.setOutputProperty(OutputKeys.METHOD,"xml");
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
t.transform(new DOMSource(doc), new StreamResult(System.out));
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
</pre>
Edited by: user12185243 on Apr 6, 2013 6:38 AM
Edited by: user12185243 on Apr 6, 2013 6:41 AM
Edited by: user12185243 on Apr 6, 2013 6:43 AM
Edited by: user12185243 on Apr 6, 2013 6:45 AM
Edited by: user12185243 on Apr 6, 2013 9:00 AMeither this way we can do this
1)
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
<b> factory.setIgnoringElementContentWhitespace(true); </b>
DocumentBuilder db = factory.newDocumentBuilder();
or
2)
java.io.StringWriter sw = new java.io.StringWriter();
StreamResult sr = new StreamResult(sw);
t.transform(new DOMSource(doc), sr);
String xml1 = sw.toString().trim();
<b> xml1=xml1.replaceAll("\\s",""); </b>
System.out.println(xml1.trim()); -
How to remove a node from a xml
Hi All,
I want to remove a node from my xml output. Can anyone suggest me how to get that? I want to implement this by using the ASSIGN activity.
My sample output is
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<env:Header>
<wsa:MessageID>urn:4EF1A350677C11E1BFA7794ED76B03EF</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
</wsa:ReplyTo>
</env:Header>
<env:Body>
<SiebelOrderQueryByExample_Output xmlns="http://siebel.com/asi/">
<ListOfOrderInterface xmlns="http://www.siebel.com/xml/Siebel%20Order">
<Orders>
<Id>1-15IXJ</Id>
<AccountId>1-2EE</AccountId>
<OrderNumber>1012-1234</OrderNumber>
<ListOfLineItems>
<LineItems>
<Id>1-15IYN</Id>
<LineNumber>303</LineNumber>
<OrderNumber>1012-1234</OrderNumber>
<OrderHeaderId>1-15IXJ</OrderHeaderId>
</LineItems>
</ListOfLineItems>
</Orders>
</ListOfOrderInterface>
</SiebelOrderQueryByExample_Output>
</env:Body>
</env:Envelope>
I want to delete the <ListOfLineItems>node from the xml above so that my resultant would be,
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<env:Header>
<wsa:MessageID>urn:4EF1A350677C11E1BFA7794ED76B03EF</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
</wsa:ReplyTo>
</env:Header>
<env:Body>
<SiebelOrderQueryByExample_Output xmlns="http://siebel.com/asi/">
<ListOfOrderInterface xmlns="http://www.siebel.com/xml/Siebel%20Order">
<Orders>
<Id>1-15IXJ</Id>
<AccountId>1-2EE</AccountId>
<OrderNumber>1012-1234</OrderNumber>
</Orders>
</ListOfOrderInterface>
</SiebelOrderQueryByExample_Output>
</env:Body>
</env:Envelope>
Please suggest something Its urgent.
Thanks in Advance.It goes something like this, taken from the above blog entry:
Removing a node from node-list
With the bpelx: extensions in BPEL you are able to insert and update nodes in a node list. A node-list is an XML message that contains a set of records. In this article I use the following example:
<BookList xmlns="http://message.vijfhuizen.com">
<Book>
<title>The Lord Of The Rings</title>
<author>J.R.R. Tolkien</author>
</Book>
<Book>
<title>Harry Potter</title>
<author>J.R.R. Tolkien</author>
</Book>
<Book>
<title>The Hobbit</title>
<author>J.R.R. Tolkien</author>
</Book>
<Book>
<title>Storm; Chronicals of Pandarve</title>
<author>Don Lawrence</author>
</Book>
</BookList>
For creating and updating node lists the bpelx: functions are enough to handle this. But when you want to remove a particular node, you can use the bpelx:remove function. But this function can only remove a node from a particular position. For example removing the second node you code:
<bpel:assign>
<bpelx:remove>
<bpelx:target variable="VarBookList" query="/Booklist/Book[2]" />
</bpelx:append>
</bpel:assign>
It is hard to code the bpelx:remove to create a xpath to dynamicly remove node. You would like to remove the second node based on the xpath:
/Booklist/Book[title="Harry Potter" and author="J.R.R. Tolkien"]
You can add the above xpath in the bpelx:remove, but you are not able to make this dynamically.
There is a solution. The trick is to create a stylesheet that copies the data into a new message, but removing that particular records. Create a stylesheet that does the normal copy of the XML message. Then add a <choose> element in the stylsheet to filter that particular record.
<xsl:template match="/">
<BookList>
<xsl:for-each select="/BookList/Book">
<xsl:choose>
<xsl:when test="title='Harry Potter' and author='J.R.R. Tolkien'"/>
<xsl:otherwise>
<Book>
<title>
<xsl:value-of select="title"/>
</title>
<author>
<xsl:value-of select="author"/>
</author>
</Book>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</BookList>
Now we have a XSL stylesheet that removes a particular record, but this is not variable. This can be done via XSLT parameters.
<xsl:param name="pTitle"/>
<xsl:param name="pAuthor"/>
<xsl:template match="/">
<BookList>
<xsl:for-each select="/BookList/Book">
<xsl:choose>
<xsl:when test="title=$pTitle and author=$pAuthor"/>
<xsl:otherwise>
<Book>
<title>
<xsl:value-of select="title"/>
</title>
<author>
<xsl:value-of select="author"/>
</author>
</Book>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</BookList>
</xsl:template>
Now we are able to use this stylesheet in BPEL. In general BPEL create the following code:
<assign name="Transform">
<bpelx:annotation>
<bpelx:pattern>transformation</bpelx:pattern>
</bpelx:annotation>
<copy>
<from expression="ora:processXSLT('RemoveNode.xsl'
, bpws:getVariableData('Variable_BookList','payload')" />
<to variable="Variable_BookListTemp" part="payload"/>
</copy>
</assign>
But this code does not pass parameters to the stylesheet. The ora:processXSLT() can do this it has an additional parameter in this function:
<assign name="Transform">
<bpelx:annotation>
<bpelx:pattern>transformation</bpelx:pattern>
</bpelx:annotation>
<copy>
<from expression="ora:processXSLT('RemoveNode.xsl'
, bpws:getVariableData('Variable_BookList','payload')" />
, bpws:getVariableData('BPELxslparameters'))"/>
<to variable="Variable_BookListTemp" part="payload"/>
</copy>
</assign>
Now only you have to create the BPELxslparameters variable and assign it with the correct name/value pairs. The structure of the this variable is as follows:
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.oracle.com/service/bpel/common"
targetNamespace="http://schemas.oracle.com/service/bpel/common"
elementFormDefault="qualified">
<xsd:element name="parameters">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="item" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="value" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Create in BPEL the variable BPELxslparameters and let it point to this strucure:
<process ....
xmlns:common="http://schemas.oracle.com/service/bpel/common"
.../>
<variable name="BPELparameters" element="common:parameters"/>
Now we can in BPEL create an empty XML message, based on this strcuture and assign the values to these parameters and then call the processXSLT function.
<bpelx:assign name="Assign_GenerateEmptyParameterSet">
<copy>
<from>
<parameters xmlns="http://schemas.oracle.com/service/bpel/common">
<item>
<name>pTitle</name>
<value/>
</item>
<item>
<name>pAutor</name>
<value/>
</item>
</parameters>
</from>
<to variable="BPELparameters" query="/common:parameters"/>
</copy>
</bpelx:assign>
<assign name="Assign_setXSLTParameters">
<copy>
<from expression="'Harry Potter'"/>
<to variable="BPELparameters" query="/common:parameters/common:item[1]/common:value"/>
</copy>
<copy>
<from expression="'J.R.R. Tolkien'"/>
<to variable="BPELparameters" query="/common:parameters/common:item[1]/common:value"/>
</copy>
</assign>
Posted by Marc Kelderman SOA Blog at 1/16/2008 09:20:00 PM -
How to remove empty tags from XML
Hello,
I have a XML file which contains some empty tags and some values with "?". I need to remove all empty tags and tags which have a value "?".
Sample Data:
<a>
<b></b>
<c> Hello </c>
<d>world ?</d>
<e>oracle</e>
</a>
Expected result:
<a>
<c> Hello </c>
<e>oracle</e>
</a>
Thank you for your time.
Thanks,
Edited by: 850749 on Apr 7, 2011 6:25 PMDear Odie,
May I make your example a bit more complicated by adding an additional complexType, please:
---Original ----
<DEPT>
<EMPID>1</EMPID>
<EMPNAME>Martin Chadderton</EMPNAME>
<SALARY>??</SALARY>
<SALARYq></SALARYq>
</DEPT>
----- New ----
<DEPT>
<EMPID>1</EMPID>
<EMPNAME>Martin Chadderton</EMPNAME>
<SALARY>??</SALARY>
<SALARYq></SALARYq>
<EMPLMNT_HISTORY>
<DEVISION>1</DEVISION>
<FROM_DATE>2011-01-01 </FROM_DATE>
<TO_DATE></TO_DATE>
</EMPLMNT_HISTORY>
</DEPT>
Your solution works perfectly for <SALARY>, but how would you suggest also to deal with <TO_DATE> ?
Massive thanks for your help!
N.B. Just to emphasise, in my case I have 3 levels (complexType > complexType > complexType) and many elements and I would like to know if there is any generic option to say
to remove all the empty elements from the result, as it causes to the SSJ (Systinet) Webservice to crash. -
How to remove empty space from a file
Hi all,
Can any one help on how to remove the blank spaces from a file.
I used trim function but unable to remove the spaces.
I have a file in which there is a name like 'JAIRAM' and am storing this file in a variable FILE_CONTENTS.
Now am unable to compare FILE_CONTENTS with another value as it is storing empty spaces also from the file.
Please help on this
Thanks,
SriniTrim only trim at the beginning or at the end. Can you try using the replace sql function.. see below..
SQL> select replace('abc def',' ','') from dual ;
REPLAC
abcdef
cheers -
How to remove empty row from rfc table output.
Hello,
I am using adaptive rfc and printing table output. The table rows start from 2nd row, the first row being empty. How can I remove the empty first row.
Here is what I tried.
wdContext.nodeDataSource().nodeTableOutput().moveNext();
and
wdContext.nodeDataSource().nodeTableOutput().moveTo(1);
Neither of them worked. Any clue is appreciated.
SrinivasIWDNodeElement first = wdContext.nodeDataSource().nodeTableOutput().getElementAt(0);
wdContext.nodeDataSource().nodeTableOutput().removeElement(first);
Armin -
How to remove empty tags from a config file
Hi all,
I have a task where we need to run a Java program to remove tags which do not contain ny information from the config files. The format of the file is as under:
<roleManager>
<providers>
<add name="AspNetSqlRoleProvider" b03f5f7f11d50a3a" />
<add name="AspNetWindowsTokenRoleProvider" PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
<httpModules>
</httpModules>
In the above lines <roleManager> is a tag which contains some data, while <httpModules> is an empty tag and does not conatin any data. The resultant should be:
<roleManager>
<providers>
<add name="AspNetSqlRoleProvider" b03f5f7f11d50a3a" />
<add name="AspNetWindowsTokenRoleProvider" PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
Please suggest how can we achieve this?
Thanks in advanceI ususally do that type of thing with a state machine... read a token, look for what is next, and if it's the closing token, I don't write it out. You have well defined opening token syntax and closing token syntax, so it should be relatively easy.
-
How to remove empty char from a string
Hi,
In my code I should get numeric int numbers and convert them to 1 and 0 , concatenate thm to make an string ( 8 chars) . the problem I have is the empty chars as result of conversion from number to string
so lets say pxiAnaIn=1 dutVdd=2 and dutOut=5 so then the output should be 10110001 but now the output is 10110 1 . could you please let me know how can I fix this problem
thankstintin_99 wrote:
Hi,
In my code I should get numeric int numbers and convert them to 1 and 0 , concatenate thm to make an string ( 8 chars) . the problem I have is the empty chars as result of conversion from number to string
so lets say pxiAnaIn=1 dutVdd=2 and dutOut=5 so then the output should be 10110001 but now the output is 10110 1 . could you please let me know how can I fix this problem
thanks
You could make your life a little easier and only use 1 format string. Use "%03b%02b%03b" for the format string. You can then expand the format string to allow multiple inputs. You will do the job of 4 functions with just 1.
"%3b" just says to give 3 spaces for the binary number. But any preceding 0s will be turned into spaces. Adding the 0 in there tells the format string to prepend 0s instead of using spaces.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
How to remove the amp: from plsql xml code
Hi All,
The XML TopUpsOrderValuationRequestVOX000001014809_20100517_15_44_10_184.xml represents the input XML.
When passed in to the database the values get stored as 10&20 .
We have to remove the existence of amp; from the database.
its very urgent..
thanks a lot..
thanks & regards
balaji.gPlease provide a small script that demonstrates what you are seeing. Include your version of Oracle as well. Use the tag (see the FAQ under your sign-in name in the upper right) to retain formatting of your script/data.
In order for others to help you properly, you need to include sufficient detail for those who can't see your screen. -
How to check empty return from Get XML Document Data?
If Get XML Document Data doesn't return a result, how do you test it? String.isEmpty() doesn't do the trick, it still throws the exception "java.lang.NullPointerException". I can't seem to be able to match that up to a cisco exception with a "On Exception Goto" step (which I put right before the XML Document Data step). Any clues anyone?
Hi,
Try this:
variable=Get XML Document Data ()
if(variable == null) then
true
false
Gabriel. -
How to remove the bookmark from the table of contents?
Hi everyone, I have a question:
How to remove the bookmark from the table of contents in Captivate 6?
Regards...Doug, your frustration is making you "bug" gun trigger happy. LOL
LOL, I suppose I have.
I believe the answer you are looking for is in the publishing preferences: under LMS advanced settings, look for the option: never send resume data.
[can someone please confirm this - I am not at a desktop now]
Anyhow, selecting this option will stop resume data - so the lesson will treat even returning learners as new. Hopefully, this will work for you.
This works! Thank you again!
*but* Why isn't Captivate asking the learner to make the choice of whether to start over or resume. It does this correctly if the lesson is published stand-alone.
Thanks again! -
How to remove the "0" from the sum cell when the other cells are empty?
Hello!
When I use the formula to sum the values from a few cells, there is a zero in the sum cell when the other cells are empty.
My question concerns how to remove the 0 from the sum cell when the cells that will be summed are empty.
Thank you!
/Johan StrömbeckHi,
Please try the Mr. Laurence's suggestion first. Then, we may try the other workarounds.
1) Go to Excel option> Advanced>Display Option for this worksheet> Uncheck Show a zero in cells that have zero value
2) Go to Conditional Formatting>New Rule>Format only cells that contain> Value equal to 0> Format the color with white
Hope it's helpful.
Regards,
George Zhao
TechNet Community Support -
How to remove a meter from an installation after move-out
Hi,
Could anyone please tell me how to remove a meter from an installation after move-out and if the installation was blocked before move-out.
I was trying to remove the meter from an installation which was blocked before move-out. And if i remove the blocking after move-out, it is still giving me this message that the installation is blocked.
Thanks in advance.
MahavirDear Birendra,
You can NEVER remove a Device (for Billing Related or FULL removal), since you need to save a Removal read while doing the removal. Hence, you can not create a MR ( Reason 01/02/03/06/16/17/21/22), without a Active contract. This is a Basic Metering Rule.
You will have to do the removal on the same day of the Move out.
Any additional questions?
KR,
AAL!
Maybe you are looking for
-
How to Use Decode with Add_months
Here is my code DECLARE no_of_rents number(3) :=0; BEGIN select (:period_mm/decode(:pay_freq,'M',1,'Q',3,'H',6,12)) into no_of_rents from dual; for i in 1..no_of_rents loop insert into mk_rnt (MK_NO,RENT_NO,DUE_DATE,DUE_AMT)
-
Firefox 3.6.8 is not remembering my user name and password
This has been happening since I bought my new iMac with snow leopard and downloaded Firefox. This does not happen with Safari. I have checked the forums and mozzilazine and google to no avail.
-
How to trace the change log for a program ? both local and release versions.
Hi experts, I encounter a very strange problem. I changed a program, created a new version TR, , there are three versions before my version which are all have been released. but there is one sentence which is not added by me, could anyone tell me how
-
How do I insert a CSV file that has blank fields? (Some fields need to be blank) CS4
Hi, this is the first time I have done a data merge in InDesign. I am trying to insert an address list that often has blank fields in it. The fields are blank since some fields are not relevent to some people (i.e. some of the people don't have cell
-
How t ocreate tax code ...?
hi all Can anybody explain me how to create tax code for my company code in IDES. I tried to create new tax code in FTXP.. System is asking for tax jusdricaton.. Please guide me how to proceed further Thanks sap-mm