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 PM

Dear 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.

Similar Messages

  • 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 AM

    either 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 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 advance

    I 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 html tags from a column

    Hi
    Problem is this: I get a column with a comma separated list of id's and I can successfully parse these id's and use them elsewhere. BUT, occasionally there are html tags within that id list like this:
    1082471,1237423<br xmlns="http://www.w3.org/1999/xhtml" />
    Is there a way to just automatically remove all tags from a column? Could do this with regex, but since there is no support, I don't know what to do.

    Hi,
    If the HTML can be detected by a starting symbol like „<“, then you could use the following:
    Unfortuntely the operation “ReplaceRange” is only available on a Text-level, so you have to invoke a function (at least to my knowledge). You also need an Index-column in your table, so if you don’t have it, you need to create one as well.
    This is your function:
    let
       fnRemoveHTML = (Value, Index) =>
    let
       Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
       IndeNo = Index,
       Value_ = Source{IndeNo-1}[Value],
       length = Text.Length(Text.From(Value_)),
       position = Text.PositionOf(Text.From(Value_), "<"),
       range = length-position,
       new= if Value_ is number then Value_ else Text.ReplaceRange(Value_, position, range, "")
    in
        new
    in
      fnRemoveHTML
    And this is how you invoke it:
    let
        Quelle = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
        Last = Table.AddColumn(Quelle, "Custom", each fn_RemoveHTML([Value], [Index])),
        ChangedType = Table.TransformColumnTypes(Last,{{"Custom", type number}})
    in
        ChangedType
    Provided your table is called “Tabelle1” & the column with your values to be replaced “Value” & your index-col “Index”
    Imke

  • How to remove HTML tags from a String ?

    Hello,
    How can I remove all HTML Tags from a String ?
    Would you please to give me a simple example ?
    Best regards,
    Eric

    Here's some code I cooked up. I have created an object that processes code so that it can be incorporated directly into a project. There is some redundancy so that the it can be used in more than one way. Depending on your situation you might have to make the condition statement a little more sophisticated to catch stray ">" tags.
    I have also included a Tester application.
    //This removes Html tags from a String either by submitting the String during construction and then
    // calling getProcessedString() or
    // by simply calling " stringwithoutTags=removeHtmlTags(stringWithTagsSubmission); "
    //Note: This code assumes that all"<" tags are accompanied by a ">" tag in the proper order.
    public class HtmlTagRemover
         private String stringSubmission,processedString,stringBeingProcessed;
         private int indexOfTagStart,indexOfTagEnd;
         public HtmlTagRemover()
         public HtmlTagRemover(String s)
              removeHtmlTags(s);          
         public String removeHtmlTags(String s)
              stringSubmission=s;
              stringBeingProcessed=stringSubmission;
              removeNextTag();
              return processedString;
         private void removeNextTag()
              checkForNextTag();
              while((!(indexOfTagStart==-1||indexOfTagEnd==-1))&<indexOfTagEnd)
                   removeTag();
                   checkForNextTag();
              processedString=stringBeingProcessed;
         private void checkForNextTag()
              indexOfTagStart=stringBeingProcessed.indexOf("<");
              indexOfTagEnd=stringBeingProcessed.indexOf(">");
         private void removeTag()
              StringBuffer sb=new StringBuffer("");
              sb.append(stringBeingProcessed);
              sb.delete(indexOfTagStart,indexOfTagEnd+1);
              stringBeingProcessed=sb.toString();
         public String getProcessedString()
              return processedString;
         public String getLastStringSubmission()
              return stringSubmission;
    public class HtmlRemovalTester
         static void main(String[] args)
              String output;
              HtmlTagRemover h=new HtmlTagRemover();
              output="The processed String: "+h.removeHtmlTags("<Html tag>This is a test<another Html tag> string<yet another Html tag>.");
              output=output+"\n"+" The original string:"+h.getLastStringSubmission();
              System.out.print(output);

  • 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

  • Remove Cdata tags from XML body

    Integration Broker message is being publish from the Peoplecode in the savepostchange event of a page......So basically when they click on the save, it is being published.
    ok, I have title field on a page and the user entered special character "&" and there is a HTML definition being used and that definition goes through parsexmlstring function.
    For example In the cust_title field on a page the user entered " A & B"
    I went to the HTML definition and wrapped cust_title field in the CDATA tags like <![CDATA[<Title>%BIND(:8)</Title>]]>
    Now , there is no error, XML is getting published. But in the xml message
    I see Cdata tags and string is appearing exactly as it was entered.....
    But how can I get rid of the Cdata tags from the XML message?

    Dear 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 SOAP tag from request going from OSB flow

    Hi,
    I need to send message to external party...I am using OSB for that. ...But the external party said they dont want any soap tag in the message as they need only required information .
    *<?xml version=”1.0” encoding=”UTF-8” ?>
    <soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope /”>
    <soapenv:Header/>
    <soap-env:Body xmlns:soap-env=”http://schemas.xmlsoap.org/soap/envelope /”>
    <TransactionAcknowledgement xmlns="">
    <TransactionId>HELLO EXTERNAL</TransactionId>
    <UserId>MC</UserId>
    <SendingPartyType>SE</SendingPartyType>
    </TransactionAcknowledgement>
    </soap-env>
    </soap-Envelope>*
    but they need only following message.
    * <TransactionAcknowledgement xmlns="">
    <TransactionId>HELLO EXTERNAL</TransactionId>
    <UserId>MC</UserId>
    <SendingPartyType>SE</SendingPartyType>
    </TransactionAcknowledgement>*
    Following are the log message printing in my log.
    Following message we have to send
    <TransactionAcknowledgement><TransactionId>HELLO EXTERNAL</TransactionId><UserId>MC</UserId><SendingPartyType>SE</SendingPartyType></TransactionAcknowledgement>>
    Then we are applying inlinedXML() on above message and getting following message
    After function fn-bea:inlinedXML
    EMCMSSL Body ::::::
    <Body xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <TransactionAcknowledgement xmlns="">
    <TransactionId>HELLO EXTERNAL</TransactionId>
    <UserId>MC</UserId>
    <SendingPartyType>SE</SendingPartyType>
    </TransactionAcknowledgement>
    </Body>
    Finally we are printing the outbound variable
    Outbound variable:
    <con:endpoint name="BusinessService$EMCNotification$BusinessService$external$PushDataBS" xmlns:con="http://www.bea.com/wli/sb/context">
    <con:service>
    <con:operation>advisory123</con:operation>
    </con:service>
    <con:transport>
    <con:uri>https://XXXX.sg:50001/XISOAPAdapter/MessageServlet</con:uri>
    <con:mode>request-response</con:mode>
    <con:qualityOfService>exactly-once</con:qualityOfService>
    <con:request xsi:type="http:HttpRequestMetaData" xmlns:http="http://www.bea.com/wli/sb/transports/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <tran:headers xsi:type="http:HttpRequestHeaders" xmlns:tran="http://www.bea.com/wli/sb/transports">
    <tran:user-header name="JMSType" value="Transaction Acknowledgement"/>
    <http:Content-Type>text/xml</http:Content-Type>
    <http:SOAPAction>""</http:SOAPAction>
    </tran:headers>
    </con:request>
    </con:transport>
    <con:security>
    <con:doOutboundWss>false</con:doOutboundWss>
    </con:security>
    </con:endpoint>>
    But I am not getting how the client is receiving soap header.
    please suggest for the same.

    Hi All.
    For removing the namespace from header I found following function but not sure how tom implement it for my requirement.
    Pleae help if possible.
    I need a XQuery function to remove name space from my xml message.
    my message is
    <Body xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <TransactionAcknowledgement xmlns="">
    <TransactionId>HELLO MSSL</TransactionId>
    <UserId>MC</UserId>
    <SendingPartyType>SE</SendingPartyType>
    </TransactionAcknowledgement>
    </Body>
    I need
    <Body xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <TransactionAcknowledgement xmlns="">
    <TransactionId>HELLO MSSL</TransactionId>
    <UserId>MC</UserId>
    <SendingPartyType>SE</SendingPartyType>
    </TransactionAcknowledgement>
    </Body>
    Function I found is
    declare namespace xf = "http://tempuri.org/vijfhuizen/com/myMessage/";
    declare function xf:strip-namespace($e as element())
    as element()
    element { xs:QName(local-name($e)) }
    for $child in $e/(@*,node())
    return
    if ($child instance of element())
    then xf:strip-namespace($child)
    else $child
    declare variable $e as element() external;
    xf:strip-namespace($e)
    I have created the function but not suire how to execute it.

  • How to remove html-tags from a text.

    Hello!
    I have a text-field which I will remove html-tag's from.
    Example:
    "This is a test<br><p> and another test"
    The function must return a similar text, but without the html-
    tags <br> and <p> (in this case).
    Anybody that can help me with this little problem?
    Thanks in advance for any help :-)
    Best regards
    Kjetil Klxve

    You can wait for some kind personal to post a complete code
    solution... But if you want to fix this yourself (which is good
    for the soul) here are some hints:
    - You can use SUBSTR to get at chunks of text
    - You can use INSTR to find particular characters.
    - You can use INSTR as an argument of SUBSTR
    Hence:
    bit_of_text := SUBSTR(text, 1, INSTR(text, '<'));
    chopped_text := SUBSTR(text, INSTR(text, '<'));
    bit_of_text := bit_of_text||SUBSTR(chopped_text, INSTR
    (text, '>'), INSTR(text, '<'));
    will give you the first bit of text that doesn't contain any
    angle brackets.
    From this you should be able to work out how to functionalised
    this (you'll need to store the offsets and use them in a loop
    construct).
    Note that this assumes that the text only contains the '<'
    character when it's part of a HTML tag. If you can't guarantee
    this then you'll have to explicitly search for all the tags e.g.
    bit_of_text := SUBSTR(text, 1, INSTR(lower(text), '<p>'));
    bit_of_text := SUBSTR(text, 1, INSTR(lower(text), '<br>'));
    This will be a bit of pain. And completely rules out XML!
    rgds APC

  • How to remove the prolog from XML in Oracle?

    Our system works like this:
    1. Pass in a piece of XML to the database as a CLOB
    2. Database converts this to XMLTYPE (stored as a CLOB (you can skip over this, Marco *{;-) ))
    3. An application then reads the XML from the database and inserts it into another bit of XML
    4. The application continues its processing based on this new composite XML.
    Up until now, the XML loaded into the database in step 1 (by various systems) has never contained a prolog. However, a new system has come along and is now passing in a prolog. This causes problems for the application in step 3.
    Aside from trying to get the new system to not pass in the prolog, is there a way to remove it from within Oracle?
    The two solutions I've come up with don't feel elegant:
    1. Use XMLTABLE to extract the main root node (which could be different, depending on which system sent in the data, and could change)
    2. Convert the prolog into a comment, using REPLACE, before converting the CLOB into an XMLTYPE.
    If I was forced to use one of these methods, I'd go with 2, but I really, really hope there's a better way of doing it.
    Has anyone got any other suggestions, please?
    PS. We're currently on 10.2.0.4 and are shortly about to move to 11.2.0.3, but the solution has to work on both versions, for added fun and excitement!

    This is the error the application gives: "Error obtaining Additional Info SAX Exception : No processing instruction starts with 'xml'" which the app dev says is due to the presence of the prolog in the middle of the xml the app has build up.So basically, the app just "pastes" the XML in the middle of another without caring about the structure? What kind of design is that?
    IMO, the app has to be fixed, not the input XML.
    Plenty about how to add the prolog, nothing about how to remove it!You can use XMLQuery function to extract the root element :
    SQL> create table tmp_xml3 of xmltype
      2  xmltype store as basicfile clob;
    Table created
    SQL> insert into tmp_xml3 values (xmltype('<?xml version="1.0" encoding="UTF-8"?><root/>'));
    1 row inserted
    SQL> select * from tmp_xml3;
    SYS_NC_ROWINFO$
    <?xml version="1.0" encoding="UTF-8"?><root/>
    SQL>
    SQL> select xmlquery('*' passing object_value returning content)
      2  from tmp_xml3;
    XMLQUERY('*'PASSINGOBJECT_VALU
    <root/>
    Edited by: odie_63 on 22 août 2012 15:26

  • How to remove an Element from XML by confirming Attribute of that element

    Hi guys
    I have an XML file where i have all users DB. Now i want to remove a user from that XML file. I want to check an user id attribute which is uniqe with existing users in XML file, if its the same user then delete this user from XML file and save the changes in XML file.
    here is my XML file:
    <?xml version="1.0" encoding="UTF-8"?>
    <users>
    <user id="zahid" password="X8UrUN79avT27LYwUESiliAV328=" name="Zahid Nawaz" phone="9599808" email="[email protected]" role="Tnr+vPuuAAsix8heVWD4mioCgLQ=" />
    <user id="Admin" name="alpha beta" password="fEqNCco3Yq9h5ZUglD3CZJT4lBs=" phone="456782656" email="[email protected]" role="Tnr+vPuuAAsix8heVWD4mioCgLQ=" />
    <user id="Guest" name="beta alpha" password="+ml3yZuAnbaOHFaIjsOL0ARxmzk=" phone="8765432" email="[email protected]" role="+s6D7jAUvcj5ggPMlOLokiJFLpA=" /><user id="Guest1" name="unknown unknown" password="+ml3yZuAnbaOHFaIjsOL0ARxmzk=" phone="123122112" email="[email protected]" role="+s6D7jAUvcj5ggPMlOLokiJFLpA=" />
    </users>for example i want to delete a user which have user id= Guest.
    How can i do it in Java. Any code example please. i am using JDOM document and SAXBuilder for parsing.
    Waiting for your replay.
    Thanks in Advance
    Best regard

    Hi,
    Till now i tried the following code which give null pointer exception at following line
    element.getParentNode().removeChild(element);
         public String removeUserByID(String id) throws Exception{
                   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                 DocumentBuilder builder = factory.newDocumentBuilder();
                 TransformerFactory tFactory = TransformerFactory.newInstance();
                 Transformer tFormer = tFactory.newTransformer();
                   doc = builder.parse(usersXml);
                 Element element = (Element)doc.getElementsByTagName("user id="+id).item(0);
    //             Remove the node
                 element.getParentNode().removeChild(element);
    //             Normalize the DOM tree to combine all adjacent nodes
                 doc.normalize();
                 FileOutputStream fos = new FileOutputStream(this.usersXml);
                   XMLOutputter out = new XMLOutputter();
                   out.output(((org.jdom.Document)doc), fos);
              /*     Source source = new DOMSource(doc);
                 Result dest = new StreamResult(System.out);
                 tFormer.transform(source, dest);
                 System.out.println();
                 return "true";
              if following line i m trying to use first attribute of my XML file where i am passing a string which is for example like "user id=Guest". id is a string which have user Id "Guest".
    Element element = (Element)doc.getElementsByTagName("user id="+id).item(0);So any suggestion??Whats wrong here?
    Best regards and thanks again 4 ur reply.

  • How to remove empty tags respecting the schema contraints?

    Hi,
    I'm generating an XML document with XSLT. This document have some empty tags. My question is about to remove all empty tags only if they are defined as optionnals in the schema.
    Is this possible with the DOM?
    Thanks in advance,
    Philippe

    With DOM3 validation api, elements/attributes may be checked if they may be removed.
    -Check if the element is empty; getFirstChild() method returns null.
    -Check if the element may be removed with DOM 3 Validation API.

  • How to remove white spaces from XML content using Coldfusion?

    Hi,
    Can anybody help me in removing white spaces in between the tags from the below XML content using coldfusion?
    XML content:
    <?xml version="1.0" encoding="UTF-8"?> <chart showdates="true" today="08/12/2009"> <phases> <phase color="CCFFCC" name="Funded"/> <phase color="CDCD67" name="Concept"/> <phase color="99CCFF" name="Feasibility"/> <phase color="0099FF" name="Development"/> <phase color="0099FF" name="Development"/> <phase color="CC99FF" name="Close-out"/> <phase color="909090" name="Sustaining"/> </phases><program name=""> <project enddate=" 30/03/2007 " id="43250" startdate=" 28/02/2006 "> <version enddate=" 30/03/2007 " number=" 1" startdate=" 28/02/2006 "> <phase color="CCFFCC" currentdate="23/03/2006" name="Project Start" plandate="28/02/2006" type="phase"/> <phase color="99CCFF" currentdate="04/04/2006" name="Feasibility Closure" plandate="31/05/2006" type="phase"/> <phase color="0099FF" currentdate="29/03/2007" name="Commercialization" plandate="30/12/2006" type="phase"/> <phase color="CC99FF" currentdate="30/03/2007" name="Project Closed" plandate="30/03/2007" type="phase"/> <phase color="909090" currentdate="" name="Obsolescence" plandate="" type="phase"/> </version> </project> </program> </chart>
    Output I am expecting is like below,
    <?xml version="1.0" encoding="UTF-8"?><chart showdates="true" today="08/12/2009"><phases><phase color="CCFFCC" name="Funded"/><phase color="CDCD67" name="Concept"/><phase color="99CCFF" name="Feasibility"/><phase color="0099FF" name="Development"/><phase color="0099FF" name="Development"/><phase color="CC99FF" name="Close-out"/><phase color="909090" name="Sustaining"/></phases><program name=""><project enddate=" 30/03/2007 " id="43250" startdate=" 28/02/2006 "><version enddate=" 30/03/2007 " number=" 1" startdate=" 28/02/2006 "><phase color="CCFFCC" currentdate="23/03/2006" name="Project Start" plandate="28/02/2006" type="phase"/><phase color="99CCFF" currentdate="04/04/2006" name="Feasibility Closure" plandate="31/05/2006" type="phase"/><phase color="0099FF" currentdate="29/03/2007" name="Commercialization" plandate="30/12/2006" type="phase"/><phase color="CC99FF" currentdate="30/03/2007" name="Project Closed" plandate="30/03/2007" type="phase"/><phase color="909090" currentdate="" name="Obsolescence" plandate="" type="phase"/></version> </project></program></chart>
    Thanks in advance,
    Regards,
    Manoz.

    Daverms,
    Thanks for the quick turn around..
    I have applied the solution what you suggested above (<cfprocessingdrirective suppresswhitespaces="yes"), still whitespaces are existing in my output.
    The output what I am getting is,
    (blue color part is my output & red color indicates whitespaces)
    <?xml version="1.0" encoding="UTF-8"?>
    <chart showdates="true" today="09/12/2009">
    <phases>
    <phase color="CCFFCC" name="Funded"/>
    <phase color="CDCD67" name="Concept"/>
    <phase color="99CCFF" name="Feasibility"/>
    <phase color="0099FF" name="Development"/>
    <phase color="0099FF" name="Development"/>
    <phase color="CC99FF" name="Close-out"/>
    <phase color="909090" name="Sustaining"/>
    </phases>
    <program name="">
    <project enddate=" 01/01/2010 " id="12059" startdate=" 20/06/2003 ">
    <version enddate=" 01/01/2010 " number=" 1" startdate=" 20/06/2003 ">
            <phase color="CCFFCC" currentdate="20/06/2003" name="Project Start" plandate="20/06/2003" type="phase"/>
            <phase color="CDCD67" currentdate="" name="Concept Closure" plandate="" type="phase"/>
            <phase color="99CCFF" currentdate="20/06/2003" name="Feasibility Closure" plandate="20/06/2003" type="phase"/>
            <phase color="F0FF00" currentdate="" name="Alpha Test" plandate="" type="milestone"/>
            <phase color="F0FF00" currentdate="26/07/2004" name="Beta Test" plandate="31/05/2004" type="milestone"/>
            <phase color="0099FF" currentdate="29/06/2005" name="Commercialization" plandate="08/12/2004" type="phase"/>
            <phase color="CC99FF" currentdate="24/02/2006" name="Project Closed" plandate="01/01/2010" type="phase"/>
            </version>
    <subproject enddate=" 16/10/2008 " id="11809" name="espWatcher Pricing Toolkit" startdate=" 01/08/2003 ">
    <version enddate=" 16/10/2008 " number=" 1" startdate=" 01/08/2003 ">
            <phase color="CCFFCC" currentdate="01/08/2003" name="Project Start" plandate="01/08/2003" type="phase"/>
            <phase color="99CCFF" currentdate="" name="Feasibility Closure" plandate="" type="phase"/>
            <phase color="0099FF" currentdate="15/06/2005" name="Commercialization" plandate="08/12/2004" type="phase"/>
            <phase color="CC99FF" currentdate="16/10/2008" name="Project Closed" plandate="16/10/2008" type="phase"/>
            </version>
    </subproject>
    <subproject enddate=" 31/12/2070 " id="35704" name="espWatcher version 2 (2005)" startdate=" 01/01/2005 ">
    <version enddate=" 31/12/2070 " number=" 1" startdate=" 01/01/2005 ">
            <phase color="CCFFCC" currentdate="01/01/2005" name="Project Start" plandate="01/01/2005" type="phase"/>
            <phase color="99CCFF" currentdate="01/07/2005" name="Feasibility Closure" plandate="01/07/2005" type="phase"/>
            <phase color="0099FF" currentdate="31/03/2006" name="Commercialization" plandate="31/03/2006" type="phase"/>
            <phase color="CC99FF" currentdate="31/12/2070" name="Project Closed" plandate="31/12/2070" type="phase"/>
            </version>
    </subproject>
    </project>
    </program>
    </chart>
    However this solution removes most of the whitespaces, I want exact output as flash file is expecting so..
    Where ever I am calling the CF functions, there I am getting the whitespaces. like below cases.
    startdate="#getProjectStartDate(sProjectIdList)#" -> output I am getting for this statement is -> " 12/09/2009 "
    Please assist me...
    Regards,
    Manoz.

  • 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,
    Srini

    Trim 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 tag.

    Hi,
    I have a scenario IDOC-XI-JDBC
    From IDOC we are using change pointers and when something has been changed then those fields are being sent out but other few empty fields were coming out and to avoid that I used mapWithDefault to avoid the empty tags as  target system used to error out.
    But now when any field is empty coming from change pointer is also being caught in mapWithDefault....whereas it is expected to send blank.
    Can anyone of you suggest any solution.
    Regards
    Ria

    Hi Ria,
    You can use if without else and check the field exist or not in the source and then map it to target.
    This is a bit tricky & if you dont feel comfortable with it, then use advanced UDF, and explicitely check ResultList.SUPPRESS object and remove it in UDF and form an output stream.
    You can use any of the two.
    Regards,
    Shri.
    <removed by moderator>
    Edited by: Mike Pokraka on Jul 28, 2008 5:05 PM

Maybe you are looking for

  • Software update quit unexpectedly after 10.7.4 update

    Hi, After doing the update to OS X 10.7.4 on my MacBook Pro, I am experiencing a few problems.  First all my applications would not open any more - almost none of them - so now I am running them all in 32-bit mode.  This also happened with Safari aft

  • XSL-1009 XSL:Version

    The following xsl sample will translate with ORAXSL without errors in one of my docs: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:import href="../generic/parsePOHeader.xsl"/> <xsl:import

  • BPA Balance Forward Bill Print Program

    Hi All, Please help me in "***Balance Forward Billing in R12***" and i done all process but bill not generate through concurrnet program. Regards, Yasir

  • Problem in getting MM data into CM

    Hi I have configured Cash Management module and integrated MM, SD with forecasting. I am able to get the SD data into the forecast but not able to see the MM data in the forecast I created PR but its level "M1" is not getting reflected in the forecas

  • Resource conflict

    Hi, I have a program in which two threads, reading from the same file, run asynchronously. The problem is that sometime the two processes try to read the file together, so is thrown an exception. I think I need something like a semaphore, a flag tell