XML: empty tag issue

I use Transformer class to convert xml Document into string representation:
StringWriter sw = new StringWriter();     
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setParameter(OutputKeys.ENCODING, "UTF-8");
transformer.transform(new DOMSource(doc), new StreamResult(sw));
but if the content of the tag is empty, the output is in this format: <tag />. Can someone know how to get the following format instead: <tag></tag>?
Thanks,

I suggest that you write a specific function to translate the string with auto-close tags to empty tags instead. It is not very difficult to do and you can look at [http://sourceforge.net/projects/light-html2xml|http://sourceforge.net/projects/light-html2xml] where you will find a similar java function to convert HTML to well-formed XML.

Similar Messages

  • XML "Document" tag issue

    In my data xml file, I get data like this:
    <?xml version='1.0' encoding='UTF-8'?>
    <Document xmlns='urn:iso:std:iso:20022:tech:xsd:pain.002.001.02' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
    In Document tag, because of this: xmlns='urn:iso:std:iso:20022:tech:xsd:pain.002.001.02', the rtf doesn't show any output. But if I manually go data xml file and remove xmlns='urn:iso:std:iso:20022:tech:xsd:pain.002.001.02', then my data xml file will be like this:
    <?xml version='1.0' encoding='UTF-8'?>
    <Document xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
    This perfectly works for me. For testing purpose, I removed it (*xmlns='urn:iso:std:iso:20022:tech:xsd:pain.002.001.02'*). As the data file is from external source, I can't control always. Can someone pls help on this?
    Thanks,
    Mani

    I also have problem with 'Document' tag:
    My xsl is like :
    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- $Header: XXMCK_FINLAND_SEPA_EFT_R51-58.xsl 2011/08/4 12:43:27 $ -->
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="no" />
    <xsl:output method="xml"/>
    <xsl:key name="contacts-by-LogicalGroupReference" match="OutboundPayment" use="PaymentNumber/LogicalGroupReference" />
    <xsl:template match="OutboundPaymentInstruction">
    <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02 pain.001.001.02.xsd">
              <pain.001.001.02>
    Here in Document tag 2 lines are there, but in xml output these lines get reversed as shown below:
    <Document xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02 C:\XMLSPY~1\pain.001.001.02.xsd" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    Can anybody plz help in this regard?

  • Is there a way to modify the style sheet so that it transforms an XML document with empty tags as tag / ?

    I have extracted some code from codeproject to
    reindent an XML document. Does anyone know how I can modify the stylesheet to make it so that the transform of an XML file will result in empty tags showing up as <tag /> instead of <tag></tag>?
    // http://www.codeproject.com/Articles/43309/How-to-create-a-simple-XML-file-using-MSXML-in-C
    MSXML2::IXMLDOMDocumentPtr FormatDOMDocument(MSXML2::IXMLDOMDocumentPtr pDoc)
    LPCSTR const static szStyleSheet =
    R"!(<?xml version="1.0" encoding="utf-8"?>)!"
    R"!(<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">)!"
    R"!( <xsl:output method="xml" indent="yes"/>)!"
    R"!( <xsl:template match="@* | node()">)!"
    R"!( <xsl:copy>)!"
    R"!( <xsl:apply-templates select="@* | node()"/>)!"
    R"!( </xsl:copy>)!"
    R"!( </xsl:template>)!"
    R"!(</xsl:stylesheet>)!";
    MSXML2::IXMLDOMDocumentPtr pXmlStyleSheet;
    pXmlStyleSheet.CreateInstance(__uuidof(MSXML2::DOMDocument60));
    pXmlStyleSheet->loadXML(szStyleSheet);
    MSXML2::IXMLDOMDocumentPtr pXmlFormattedDoc;
    pXmlFormattedDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60));
    CComPtr<IDispatch> pDispatch;
    HRESULT hr = pXmlFormattedDoc->QueryInterface(IID_IDispatch, (void**)&pDispatch);
    if (SUCCEEDED(hr))
    _variant_t vtOutObject;
    vtOutObject.vt = VT_DISPATCH;
    vtOutObject.pdispVal = pDispatch;
    vtOutObject.pdispVal->AddRef();
    hr = pDoc->transformNodeToObject(pXmlStyleSheet, vtOutObject);
    //By default it is writing the encoding = UTF-16. Let us change the encoding to UTF-8
    // <?xml version="1.0" encoding="UTF-8"?>
    MSXML2::IXMLDOMNodePtr pXMLFirstChild = pXmlFormattedDoc->GetfirstChild();
    // A map of the a attributes (vesrsion, encoding) values (1.0, UTF-8) pair
    MSXML2::IXMLDOMNamedNodeMapPtr pXMLAttributeMap = pXMLFirstChild->Getattributes();
    MSXML2::IXMLDOMNodePtr pXMLEncodNode = pXMLAttributeMap->getNamedItem(_T("encoding"));
    pXMLEncodNode->PutnodeValue(_T("UTF-8")); //encoding = UTF-8
    return pXmlFormattedDoc;
    Or, if there is some other method for reindenting a MSXML2::IXMLDOMDocumentPtr object where I can specify how I want empty tags to be stored, that would be great too.  However, I don't want it to lose its status of an MSXML2::IXMLDOMDocumentPtr object.
     I.e. I would like to still perform operations on the result as if it was still an MSXML2::IXMLDOMDocumentPtr object.
    Thanks,
    A
    Adrian

    If anyone is interested, I got an answer on StackOverflow
    here.
    Adrian

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

  • How to delete empty tags after xml-import

    Hello collegues,
    I'm totally new in this forum so excuse me if I make a mistake, but I've a little question.
    I've imported text and images with a xml-import but sometimes empty tags (the colored invisible blocks) are in my text, with the result that I can't Find/Change on double-returns.
    Does anybody know an awnser to this matter? I would love to write an apple-script that will find/change this so i don't have to look after all my pages.
    Thank you very much in advance.

    ThePictureCreator wrote:
    ...I can't Find/Change on double-returns.
    What's your search query? I think you should be able to, with either a grep find of "\r+" or a normal text find of "^p^p". InDesign pretends like the tag-holding characters aren't there for the purpose of search. But you will lose the empty elements along with the extra returns. Maybe that is the problem?
    Jeff

  • Not getting empty tags in XML output

    Hello,
    I am using DBMS_XMLQuery.getXML function and cusor function in my select statement to generate XML documents. If the column value is null, the XML document is not generating a empty tag. How do I generate empty tags?
    My query is :-
    SELECT
    MSG_NAME ,MSG_DATE, BATCH_ID,
    cursor (SELECT ACTION_CODE,PART_NUMBER,
    ITEM_DESCRIPTION,ITEM_STATUS
    UOM,CONVERSIONS,INSPECTION_FLG
    FROM ITEM_OUT ITEM
    WHERE ITEM.BATCH_ID= ECF.MSG_BATCH_ID
    ) as item_header
    FROM FILE_CONTROL ECF
    null

    You need to set the option to use a null indicator. By default, null values omit their elements. With the null indicator, they are included as empty elements with a NULL="Y" attribute flag.

  • Error during XML = ABAP conversion, empty tag

    Hi.
    Im sending data from a Data Base to a proxy using BI.
    But when I get an empty response from the data base wich gives me an empty XML tag the proxy shows me an error:
    -PARSE_APPLICATION_DATA Error during XML => ABAP conversion (Response  Message; error ID: CX_ST_MATCH_ELEMENT;
    -Error during XML => ABAP conversion (Response Message; error ID: CX_ST_MATCH_ELEMENT;
    -System expected the end of the element 'STMT_DC_response'          
    This is the message that originates the fail:
    <?xml version="1.0" encoding="utf-8" ?>
    <ns0:MT_PRV23_BS_desg_response xmlns:ns0="urn:tompla-com:xi:ventas_SD">
    <STMT_response>
      <row>
       <TIPO>P</TIPO>
       <NUM_OT>55062330</NUM_OT>
       <NUM_DESGLOSE>1</NUM_DESG>
       <CANT_DESG>1724000</CANT_DESG>
      </row>
    </STMT_response>
    <STMT_DC_response />
    </ns0:MT_PRV23_BD_desg_response>
    In case that the tag is filled runs ok
    <?xml version="1.0" encoding="utf-8" ?>
    <ns0:MT_PRV23_BD_desg_response xmlns:ns0="urn:tompla-com:xi:ventas_SD">
      <STMT_response>
       <row>
        <TIPO>P</TIPO>
        <NUM_OT>55062330</NUMERO_OT>
        <NUM_DESG>1</NUM_DESG>
        <CANT_DESG>1724000</CANT_DESG>
       </row>
      </STMT_response>
      <STMT_DC_response>
       <row>
        <TIPO>P</TIPO>
        <NUMERO_OT>55062330</NUMERO_OT>
        <NUMERO_DESGLOSE />
        <COD_CAR_ADICIONA>8</COD_CAR_ADICIONA>
        <PORC_CAR_ADICION>1</PORC_CAR_ADICION>
      </row>
      </STMT_DC_response>
    </ns0:MT_PRV23_BD_desg_response>
    The definition for the data is:
    STMT_DC_response        0..1
      row                               0..n
        tipo                             0..1
    Thanks for the help you can give me about my problem with empty tags.

    I moved this question to other forum
      Expert Forums  » SAP NetWeaver  » Exchange Infrastructure 

  • XML - ABAP conversion, empty tag

    Hi.
    Im sending data from a DB to a proxy using XI.
    But when I get an empty response from the DB, wich gives me an empty XML tag the proxy shows me an error:
    -PARSE_APPLICATION_DATA Error during XML => ABAP conversion (Response  Message; error ID: CX_ST_MATCH_ELEMENT;
    -Error during XML => ABAP conversion (Response Message; error ID: CX_ST_MATCH_ELEMENT;
    -System expected the end of the element 'STMT_DC_response'          
    This is the message that originates the fail:
    <ns0:MT_xxx_response xmlns:ns0="urn:s-com:xi:SD">
    <STMT_response>
      <row>
       <c11>P</c11>
       <c12>55062330</c12>
       <c13>1</c13>
      </row>
    </STMT_response>
    <STMT_DC_response />
    </ns0:MT_xxx_response>
    In case that the tag is filled runs ok
    <ns0:MT_xxx_response xmlns:ns0="urn:s.com:xi:SD">
      <STMT_response>
       <row>
        <c11>P</c11>
        <c12>55062330</c12>
        <c13>1</c13>
       </row>
      </STMT_response>
      <STMT_DC_response>
       <row>
        <c21>P</c21>
        <c22>55062330</c22>
        <c23 />
      </row>
      </STMT_DC_response>
    </ns0:MT_xxx_response>
    The definition for the data is:
    STMT_DC_response        0..1
      row                               0..n
        tipo                             0..1
    Thanks for the help you can give me about my problem with empty tags.

    thanks for your help!
    yes, The definition for the data is:
    STMT_DC_response    0..1
    to be sure I disabled that node, so I wont get it from the DB, and It was ok
    this is ok:
    <ns0:MT_xxx_response xmlns:ns0="urn:s-com:xi:SD">
    <STMT_response>
    <row>
    <c11>P</c11>
    <c12>55062330</c12>
    <c13>1</c13>
    </row>
    </STMT_response>
    </ns0:MT_xxx_response>
    but this is not
    <ns0:MT_xxx_response xmlns:ns0="urn:s-com:xi:SD">
    <STMT_response>
    <row>
    <c11>P</c11>
    <c12>55062330</c12>
    <c13>1</c13>
    </row>
    </STMT_response>
    <STMT_DC_response />
    </ns0:MT_xxx_response>

  • How to suppress an empty tag in the XML

    Hi gurus,
    Please help me with this problem. A part of my XML output looks like this,
    <ParentElement>
    <ChildElement>The Data</ChildElement>
    <ChildElement>The Data</ChildElement>
    </ParentElement>
    This is produced in a select XMLAgg() statement from a table. If the table has one or more rows, I get the above result. But if there is no data in the table, I will get
    <ParentElement/>. But the schema is such that if the ParentElement is there, it requries at least one ChildElement so the XML file does not validate. Is there a way to suppress the ParentElement when there is no data in the table? Or should the schema be changed?
    Thanks a lot.
    Ben

    Thank you very much for your fast response. Here is the code that I use to generate the XML. At issue is the "PersonPhysicalFeature" element.
    create or replace function fnGetLivescanDataForBCA (
         p_BookingNo     in     varchar2,
         p_MniID          in     number
    return Clob
    as
         v_XMLForBCA                    Clob := null;
         v_BookingAgencyORI      constant     varchar2(10) := '0620000';
         v_DateFormat          constant     varchar2(10) := 'mm/dd/yyyy';
         v_DateTimeFormat     constant     varchar2 (25) := 'mm/dd/yyyy hh24:mi';
         v_BCADateFormat          constant     varchar2(10) := 'yyyymmdd';
         v_UnknownBOP          constant     varchar2(2) := 'XX';
         v_UnknownCC          constant     varchar2(2) := 'XX';
         v_XMLFile                    XMLType;
         v_created                    boolean := false;
         --- BCA insists on having the XML prolog
         v_XMLProlog constant varchar2(100) := '<?xml version="1.0" encoding="UTF-8"?>' || utl_tcp.CRLF ;     
    begin
         select XMLElement("BookSubject",
              XMLForest('DAVE FENNER' as "AttentionPerson"),
              XMLElement("AttentionOrganization",
                   XMLForest(v_BookingAgencyORI as "OrganizationORIID")
              XMLForest('N' as "PalmprintAvailableIndicator",
                   'Y' as "ArrestPhotoAvailableIndicator",
                   'ARMED AND DANGEROUS' as "IdentificationComments",
                   'N' as "InterstateCustodyTransferInd",
                   '192.168.95.11' as "SourceComputerSystemAddress"),
              XMLElement("Booking",
                   XMLForest(to_char(b.arrival_date, v_BCADateFormat ) as "ActivityDate"),               
                   XMLElement("BookingAgencyRecordID",
                        XMLForest(substr(b.booking_no, 1, 4) || substr(b.booking_no, 7,6) as "ID")                         
                   XMLElement("BiometricDeviceRecordID",
                        XMLForest(b.booking_no as "ID")
                   XMLElement("BookingAgency",
                        XMLForest(v_BookingAgencyORI as "OrganizationORIID")
                   XMLElement("BookingSubject",
                        (select XMLElement("PersonName",
                                  XMLForest(substr(first_name, 1, 30) as "PersonGivenName",
                                       substr(middle_name, 1,30) as "PersonMiddleName",
                                       substr(last_name,1, 30) as "PersonSurName")
                             from name
                             where mni_id = p_MniID
                             ),-- end of select name                    
                        (select XMLElement("PersonBirthDate",
                                  to_char(m.dob, v_BCADateFormat)
                             from name m                         
                             where m.mni_id = p_MniID                    
                             ), -- end of select alias
                        (select XMLAgg(
                                  XMLElement("PersonBirthDate",
                                       to_char(ma.alias_dob, v_BCADateFormat)
                             ) -- end of XMLAgg - required for multiple rows     
                             from name_alias ma     
                             where ma.mni_id = p_MniID
                             ), -- end of select alias dob
                        (select XMLElement("PersonBirthLocationCode",
                                  NVL(m.birth_state, v_UnknownBOP))
                             from name m
                             where m.mni_id = p_MniID
                             ), -- end of select birth state
                        XMLElement("PersonAssignedIDDetails",
                             (select XMLElement("PersonSSNID",
                                       XMLForest(m.ssn as "ID")
                                  from name m
                                  where m.mni_id = p_MniID
                                  ), -- end of select name.ssn     
                             (select XMLAgg(
                                       XMLElement("PersonSSNID",
                                            XMLForest(ms.ssn as "ID")
                                       ) -- end of XMLAgg
                                  from name_ssn ms
                                  where ms.mni_id = p_MniID and rownum <= 3               
                                  ), -- end of select alias SSN
                             (select XMLElement("PersonOtherID",
                                       XMLElement("ID", m.slco_pin),
                                       XMLElement("IDSourceOrganization",
                                            XMLForest(v_BookingAgencyORI as "OrganizationORIID")
                                  from name m
                                  where m.mni_id = p_MniID
                                  ), -- end of select name.slco_pin as OtherID
                             XMLElement("BookingAgencyPersonID",
                                  XMLForest('123456789' as "ID",
                                       'RCSO Some ID' as "IDTypeDescriptionText"),
                                  XMLElement("IDSourceOrganization",
                                       XMLForest(v_BookingAgencyORI as "OrganizationORIID")
                                  ) -- end of BookingAgencyPersonID
                             ), -- end of ID Details     
                        (select XMLElement("PersonPhysicalDetails",
                                  XMLForest(m.eye_color as "PersonEyeColorCode",
                                       m.hair_color as "PersonHairColorCode",
                                       m.sex as "PersonSexText",
                                       m.race as "PersonRaceCode"),                              
                                  XMLElement("PersonPhysicalFeature",
                                       (select XMLAgg(
                                                 XMLElement("PhysicalFeatureDescriptionText",
                                                      substr(smt.bodypart || ' ' || smt.description, 1, 10)
                                                      ) -- end of feature desc text
                                                 ) -- end of XMLAgg
                                            from name_smt smt
                                            where smt.mni_id = p_MniID and rownum <= 10
                                            ) -- end of select smt
                                       ), -- end of element physical feture                              
                                  XMLElement("PersonHeightMeasure",
                                       XMLForest(NVL(to_char(m.height_feet), '0') || lpad(NVL(to_char(m.height_inches), '0'), 2, '0') as "Measure")
                                       ), --- end of height                         
                                  XMLElement("PersonWeightMeasure",
                                       XMLForest(m.weight as "Measure")
                                       ) -- end of weight
                                  ) -- end of first element                         
                             from name m
                             where m.mni_id = p_MniID
                             ), -- end of select physical details
                        (select XMLElement("PersonBiometricDetails",
                                  XMLelement("PersonFingerprintSet",
                                       XMLForest(Decode(m.PERSONTYPE, 1, 'A', 2, 'J', 3, 'C', 'A')
                                       as "BiometricDescriptionText")
                                       ) -- end of second element
                                  ) -- end of first element
                             from name m
                             where m.mni_id = p_MniID
                             ), -- select PersonType               
                        (select XMLAgg(
                                  XMLElement("PersonAlias",
                                  XMLElement("PersonName",
                                       XMLForest(substr(ma.first_name, 1, 30) as "PersonGivenName",
                                       substr(ma.middle_name, 1, 30) as "PersonMiddleName",
                                       substr(ma.last_name, 1, 30) as "PersonSurName"))
                                  ) -- end of element
                             ) -- end of AMLAgg
                             from name_alias ma
                             where ma.mni_id = p_MniID
                             ), -- end of select name_alias
                        XMLElement("SubjectSupervision",
                             XMLElement("SupervisionSubjectStatus",
                                  XMLForest(to_char(b.date_booked, v_BCADateFormat) as "StatusDate",
                                       'FROM RAMSEY COUNTY LEC' as "StatusDescriptionText")
                             ) -- end pf element subject supervision
                        ---XMLelement("PersonCitizenshipCode",
                        --     v_UnknownCC
                        --     ) -- end of element
                        ), -- end of BookingSubject
                        XMLElement("TreatAsAdultIndicator", 'Y'),
                        (select XMLAgg(
                                  XMLElement("BookingCharge",
                                       XMLElement("ChargeText", substr(ct.statute_no, 1, 25)),
                                       XMLElement("ChargeDescriptionText", substr(trim(ct.charge), 1, 60)),
                                       XMLElement("ChargeClassification",
                                            XMLForest(ct.class as "ChargeDegreeText")),
                                       XMLElement("ChargeInstrument",
                                            XMLElement("DocumentDescriptiveMetadata",
                                                 XMLForest(ct.complaint_no as "DocumentID"))),
                                  ---     XMLElement("ChargeSentence", ' '),     --- do not include
                                       XMLElement("ChargeStatute",
                                            XMLForest('C' as "StatuteOffenseCode")),
                                       XMLElement("ChargeCommentsText", substr(ct.comments, 1, 50)),
                                       XMLElement("OffenseDate",
                                            to_char(NVL(ad.ucr_reported_date, ad.date_arrested), v_BCADateFormat)),
                                       XMLElement("ChargeOriginatingAgencyRID", ct.complaint_no),
                                       XMLElement("ChargeOriginatingAgency",
                                            XMLForest(ct.originating_agency as "OrganizationORIID")
                                       XMLElement("ArrestDispositionText", '205')
                             ) -- end of XMLAgg
                             from charges_temp ct
                             where ct.booking_no = p_BookingNo and ct.charge is not null
                                  and length(ct.complaint_no) <= 8
                             ), -- end of select charges
                   XMLElement("ArrestAgency",
                        XMLForest(NVL(ad.arresting_agency, v_BookingAgencyORI) as "OrganizationORIID"))
                   ), --- end of Booking
              XMLElement("BCACriminalHistoryRequestInd", 'N'),
              XMLElement("FBICriminalHistoryRequestInd", 'N'),
              XMLElement("WantWarrantSearchRequestInd", 'N')
              ) into v_XMLFile      --- .getClobVal() into v_XMLForBCA --- v_XMLFile      ----- end of BookSubject
         from Booking b
         inner join arrest_affidavit ad
         on b.booking_no = ad.booking_no     
         where b.booking_no = p_BookingNo;
         ---v_created := DBMS_XDB.createResource('/public/' || p_BookingNo || '.xml', v_XMLFile);
         v_XMLForBCA := v_XMLFile.getClobVal();
         v_XMLForBCA := v_XMLProlog || v_XMLForBCA;     
         v_XMLFile.isSchemaValid('http://isora1.co.ramsey.mn.us:8080/sys/schemas/SSI/Schema.xsd');
         if v_XMLFile.isSchemaValid = 1 then
              dbms_output.put_line('XML is valid');
         else
              dbms_output.put_line('XML is not valid');
         end if;
         return v_XMLForBCA;
    exception
         when others then
              dbms_output.put_line(SQLErrM(SQLcode));
              return null;
    end fnGetLivescanDataForBCA;
    /

  • How to generate empty tag using XMLForest

    Hi,
    I am creating an XML document using XMLAgg, XMLForest and XMlElement functions.
    At some point I have an XMLForest embedded in the other XMLForest
    XMLForest( e.indicator as "col1",
               e.participant_id as "col2",
      XMLForest( tableAlias.col11 as "address1",
                 tableAlias.col12 as "address2",            
               ) as "items",
    )           and within the last one I have some expressions which are empty, so the XML tags are not generated, however I have to have an empty tags:
    <address2></address2>I tried to replace an expression using "NVL" or "DECODE", but the results were the same.
    I also tried to replace an embedded XMLForest with an XMLElement :
    XMLForest( e.indicator as "col1",
               e.participant_id as "col2",
      *XMLElement("items"*
                 *XMLElement("address1"),*
                 *XMLElement("address2")*
               *) as "items",*)           however it created 2 <items> tags :
        <items>
             <items>
                <address1>value</address1>
                <address2></address2>
             </items>
         </items> I am working with Oracle 11.2.0 db.
    Is there any way to generate an empty tag when using XMLForest function?
    thank you in advance.
    Edited by: user624274 on Apr 3, 2013 8:52 AM
    Edited by: user624274 on Apr 3, 2013 8:53 AM

    Hello Odie_63.
    Your argument is valid, but it does not mean the solution I provided is bad.
    If you are concerned about the size of the result, it is simple, you can use like:
    REPLACE(XMLForest( NVL(e.indicator, '#NULLValue#') as "col1",  NVL(e.participant_id, '#NULLValue#') as "col2").getClobVal(), '#NULLValue#', '')
    According to Oracle documentation, REPLACE is smart and will return a CLOB (not a varchar2) because it changes the type of return according to the type of the first parameter. So you will not have issues with size.
    I believe the first question was related to use the final result to record to a table or send to another system (to use as integration). If it will be used just in a select field, it does not matter if it is not there or if it is there as NULL, the select of the field will always return ''.
    Other hint, I never use xmltype to store on database, because it is not compatible with other databases or integration tools. I use CLOB because it is the natural serialization of the object and I can convert and work with it inside and outside Oracle.
    But that is up to the architect and/or developer. If the system is running only on Oracle and there is no integration, maybe xmltype will save a lot of time in conversions.
    Regards.
    Rodolpho

  • Empty Collections and Empty Tags

    It seems that empty collections from a cast or cursor result in an empty tag. For example, the following sql:select work.work_id medlineid,
    cursor(
    select
    databankname,
    db.accessionnumberlist_ref.accessionnumberlist accessionnumberlist
    from table(dbl.databanks) db
    order by databankname) databanklist,
    cast( multiset (
    select chemical_t(
    wrkchm.cas_registry_number,
    wrkchm.term)
    from work_chemicals wrkchm
    where wrkchm.work_id=work.work_id
    order by wrkchm.term) as chemicals_t) chemicallist
    from
    works work,
    databanklist_t_v dbl
    where
    work.work_id = 96264942
    and work.work_id = dbl.work_id(+)results in the following XML:<medlinecitationset>
    <medlinecitation num="1">
    <medlineid>96264942</medlineid>
    <databanklist/>
    <chemicallist/>
    </medlinecitation>
    </medlinecitationset>Is there a way to not have these empty tags appear?
    Thanks! -- John.
    null

    David, this is about understanding the use of, and differencies between tags and collections. This is a bit hard for many new users.
    First of all searching for collections and tags can *not* be done simultaneously. You can either work with one collection only, or you can search for pictures with one or more tags.
    Next collections should be used as either temporary work sets or for special occasions like specific vacations, trips or birthdays, e.g. "Anna 5 years". You say you have a collection named "Churches". I think would have made a TAG called "Churches" instead, because a tag is for general searches that can be combined. On the other hand I might have made a collection called "Church visits July 2005" or "Summer vacation 2005" or the like.
    Another difference is that pictures in a collection can be sorted manually by drag & drop, while pictures found via tags always are shown in the order chosen in the Photo Browser Arrangement box shown bottom left in the Organizer.

  • Not inlcude empty tag while invoking service from ESB

    The ESB receives a request with input xml which contains some empty tag. while ESB invokes the actual services the empty tags should not be included. can any one help how to achieve this?

    define that tag as optional in schema and don't map that element. This should help you.
    -Ramana.

  • Error While trying to Get XML element(tag) Values

    We are trying to get XML element (TAG) value from the XML pay load.
    Example.
    Getting XML String from a web service and then converting into XML payload.
    ora:parseEscapedXML(bpws:getVariableData('signOn_Out','signOnReturn'))
    From this XML payload we are trying to get an element (Tag) value.
    We are getting following error
    Error in evaluate <from> expression at line "130". The result is empty for the XPath expression : "/client:TririgaProcessResponse/client:User/client:LastName".
    oracle.xml.parser.v2.XMLElement@118dc2a
    {http://schemas.xmlsoap.org/ws/2003/03/business-process/}selectionFailure" has been thrown.
    - <selectionFailure xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    - <part name="summary">
    <summary>
    empty variable/expression result.
    xpath variable/expression expression "/client:TririgaProcessResponse/client:User/client:LastName" is empty at line 130, when attempting reading/copying it.
    Please make sure the variable/expression result "/client:TririgaProcessResponse/client:User/client:LastName" is not empty.
    </summary>
    </part>
    </selectionFailure>
    Here are signOnReturn and XML Payload XSD's
    <schema attributeFormDefault="unqualified"
         elementFormDefault="qualified"
         targetNamespace="http://xmlns.oracle.com/Web1"
         xmlns="http://www.w3.org/2001/XMLSchema">
         <element name="Web1ProcessRequest">
              <complexType>
                   <sequence>
                        <element name="userName" type="string"/>
    <element name="password" type="string"/>
                   </sequence>
              </complexType>
         </element>
         <element name="Web1ProcessResponse">
              <complexType>
                   <sequence>
                        <element name="result" type="string"/>
                   </sequence>
              </complexType>
         </element>
    </schema>
    <?xml version="1.0" encoding="windows-1252" ?>
    <schema attributeFormDefault="unqualified"
         elementFormDefault="qualified"
         targetNamespace="http://xmlns.oracle.com/Web"
         xmlns="http://www.w3.org/2001/XMLSchema">
         <element name="TProcessResponse">
              <complexType>
                   <sequence>
                        <element name="result" type="string"/>
    <element name="User">
    <complexType>
                   <sequence>
                        <element name="Id" type="string"/>
    <element name="CompanyId" type="string"/>
    <element name="SecurityToken" type="string"/>
    <element name="FirstName" type="string"/>
    <element name="LastName" type="string"/>
    </sequence>
    </complexType>
    </element>
                   </sequence>
              </complexType>
         </element>
    </schema>

    I am sure and can see the data in audit trail.
    [2006/12/12 09:17:36]
    Updated variable "signOn_Output"
    - <signOn_Output>
    - <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="payload">
    - <WebMethodsProcessResponse xmlns="http://xmlns.oracle.com/WebMethods">
    <Result xmlns="">
    Success
    </Result>
    - <User xmlns="">
    <Id>
    2694069
    </Id>
    <CompanyId>
    208133
    </CompanyId>
    <SecurityToken>
    1165936654605
    </SecurityToken>
    <FirstName>
    Jagan
    </FirstName>
    <LastName>
    Rao
    </LastName>
    </User>
    </WebMethodsProcessResponse>
    </part>
    </signOn_Output>
    Copy details to clipboard
    [2006/12/12 09:17:36]
    Updated variable "tririga"
    - <tririga>
    - <TririgaProcessResponse xmlns="http://xmlns.oracle.com/WebMethods">
    <Result xmlns="">
    Success
    </Result>
    - <User xmlns="">
    <Id>
    2694069
    </Id>
    <CompanyId>
    208133
    </CompanyId>
    <SecurityToken>
    1165936654605
    </SecurityToken>
    <FirstName>
    Jagan
    </FirstName>
    <LastName>
    Rao
    </LastName>
    </User>
    </TririgaProcessResponse>
    </tririga>
    Copy details to clipboard
    [2006/12/12 09:17:36]
    Updated variable "Variable_2"
    - <Variable_2>
    - <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="payload">
    - <TririgaProcessResponse xmlns="http://xmlns.oracle.com/WebMethods">
    <Result xmlns="">
    Success
    </Result>
    - <User xmlns="">
    <Id>
    2694069
    </Id>
    <CompanyId>
    208133
    </CompanyId>
    <SecurityToken>
    1165936654605
    </SecurityToken>
    <FirstName>
    Jagan
    </FirstName>
    <LastName>
    Rao
    </LastName>
    </User>
    </TririgaProcessResponse>
    </part>
    </Variable_2>
    Copy details to clipboard
    [2006/12/12 09:17:36]
    Error in evaluate <from> expression at line "130". The result is empty for the XPath expression : "/client:TririgaProcessResponse/client:User/client:LastName".
    oracle.xml.parser.v2.XMLElement@1c8768e
    Copy details to clipboard
    [2006/12/12 09:17:36]
    "{http://schemas.xmlsoap.org/ws/2003/03/business-process/}selectionFailure" has been thrown.
    - <selectionFailure xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    - <part name="summary">
    <summary>
    empty variable/expression result.
    xpath variable/expression expression "/client:TririgaProcessResponse/client:User/client:LastName" is empty at line 130, when attempting reading/copying it.
    Please make sure the variable/expression result "/client:TririgaProcessResponse/client:User/client:LastName" is not empty.
    </summary>
    </part>
    </selectionFailure>
    Copy details to clipboard

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

  • XML File Tags Validation Using Oracle.

    Dear Forum Members,
    I have a doubt regarding XML File Tags Validation.
    First I will explain My Requirement.
    1. I have to generate an XML File in a Predefined Format.
    2. User will add some data in the elements, or he may copy the same elements and change to some data like
    <Emp><Empno>10</Empno></Emp>
    The above tag will be generated by the application.
    User will copy the same and change to
    <Emp><Empno>20</Empno></Emp>.
    Now he want to Upload the Changed XML File to the Database table. This is done by parsing the XML File.
    The Creation and Parsing section is over. But before Parsing I want to check for the Validation of the XML Tag. i.e. whether the tag he has copied <Emp><Empno>10</Empno></Emp> is chaned by mistake to
    <Emp><Empno>10</Empno></Emps> or some other Mistakes.
    What I have to Do..
    Regards
    Madhu K

    I still think that my previous response is valid:
    If you e.g. include (concat) your DTD in your XML it will be validated against it!
    See e.g.:
    michaels>  select xmltype (xml_dtd || your_xml) your_validated_xml
      from (select '<SSDDATA>
                     <KEY><![CDATA[6707]]></KEY>
                     <FINISHED><![CDATA[This is a Finished data ]]></FINISHED>
                     <DEFAULT></DEFAULT>
                     <MIN></MIN>
                     <MAX></MAX>
                     <UNIT></UNIT>
                     <FORMULA></FORMULA>
                     <FORMULA></FORMULA>
                     <FORMULA-DESC></FORMULA-DESC>
                     <ADVANCED-FORMULA></ADVANCED-FORMULA>
                     <INTERNAL-ADAPT-DESC></INTERNAL-ADAPT-DESC>
                     <DATA-DESC-REPORT></DATA-DESC-REPORT>
                     <REV-DESC></REV-DESC>
                    </SSDDATA>' your_xml,
                   '<?xml version="1.0"?>
                    <!DOCTYPE SSDDATA [
                      <!ELEMENT SSDDATA (KEY,FINISHED,DEFAULT,MIN,MAX,UNIT,(FORMULA)+,FORMULA-DESC,ADVANCED-FORMULA,INTERNAL-ADAPT-DESC,DATA-DESC-REPORT,REV-DESC)>
                      <!ATTLIST SSDDATA xmlns CDATA #FIXED "">
                      <!ELEMENT KEY (#PCDATA)>
                      <!ATTLIST KEY xmlns CDATA #FIXED "">
                      <!ELEMENT FINISHED (#PCDATA)>
                      <!ATTLIST FINISHED xmlns CDATA #FIXED "">
                      <!ELEMENT DEFAULT EMPTY>
                      <!ATTLIST DEFAULT xmlns CDATA #FIXED "">
                      <!ELEMENT MIN EMPTY>
                      <!ATTLIST MIN xmlns CDATA #FIXED "">
                      <!ELEMENT MAX EMPTY>
                      <!ATTLIST MAX xmlns CDATA #FIXED "">
                      <!ELEMENT UNIT EMPTY>
                      <!ATTLIST UNIT xmlns CDATA #FIXED "">
                      <!ELEMENT FORMULA EMPTY>
                      <!ATTLIST FORMULA xmlns CDATA #FIXED "">
                      <!ELEMENT FORMULA-DESC EMPTY>
                      <!ATTLIST FORMULA-DESC xmlns CDATA #FIXED "">
                      <!ELEMENT ADVANCED-FORMULA EMPTY>
                      <!ATTLIST ADVANCED-FORMULA xmlns CDATA #FIXED "">
                      <!ELEMENT INTERNAL-ADAPT-DESC EMPTY>
                      <!ATTLIST INTERNAL-ADAPT-DESC xmlns CDATA #FIXED "">
                      <!ELEMENT DATA-DESC-REPORT EMPTY>
                      <!ATTLIST DATA-DESC-REPORT xmlns CDATA #FIXED "">
                      <!ELEMENT REV-DESC EMPTY>
                      <!ATTLIST REV-DESC xmlns CDATA #FIXED "">
                    ]>' xml_dtd
              from dual)
    YOUR_VALIDATED_XML                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
    <?xml version="1.0"?>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                    <!DOCTYPE SSDDATA [                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                      <!ELEMENT SSDDATA (KEY,FINISHED,DEFAULT,MIN,MAX,UNIT,(FORMULA)+,FORMULA-DESC,ADVANCED-FORMULA,INTERNAL-ADAPT-DESC,DATA-DESC-REPORT,REV-DESC)>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                      <!ATTLIST SSDDATA xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ELEMENT KEY (#PCDATA)>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ATTLIST KEY xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ELEMENT FINISHED (#PCDATA)>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                      <!ATTLIST FINISHED xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                      <!ELEMENT DEFAULT EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ATTLIST DEFAULT xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ELEMENT MIN EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ATTLIST MIN xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ELEMENT MAX EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ATTLIST MAX xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ELEMENT UNIT EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                      <!ATTLIST UNIT xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                      <!ELEMENT FORMULA EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ATTLIST FORMULA xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                      <!ELEMENT FORMULA-DESC EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                      <!ATTLIST FORMULA-DESC xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                      <!ELEMENT ADVANCED-FORMULA EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                      <!ATTLIST ADVANCED-FORMULA xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                      <!ELEMENT INTERNAL-ADAPT-DESC EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ATTLIST INTERNAL-ADAPT-DESC xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                      <!ELEMENT DATA-DESC-REPORT EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                      <!ATTLIST DATA-DESC-REPORT xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                      <!ELEMENT REV-DESC EMPTY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                      <!ATTLIST REV-DESC xmlns CDATA #FIXED "">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                    ]><SSDDATA>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                     <KEY><![CDATA[6707]]></KEY>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
                     <FINISHED><![CDATA[This is a Finished data ]]></FINISHED>                                                                                                                                                                                                                                                                            

Maybe you are looking for