How to print an XML element empty as a < elem > < / elem > rather than < elem / >

Here's the code that creates the XML with an empty tag org.w3c.dom and fate as a text:
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();
doc.setXmlStandalone(true);
                        
Element root = doc.createElement("root");
doc.appendChild(root);
                        
Element emptyElement = doc.createElement("emptyElement");
root.appendChild(emptyElement);
            
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
StringWriter sw = new StringWriter();
StreamResult streamResult = new StreamResult(sw);
DOMSource domSource = new DOMSource(doc);
trans.transform(domSource, streamResult);

System.out.println(sw.toString());
Here is the result:
<? XML version = "1.0" encoding = "UTF-8"? >
< root >
< emptyElement / >
< / root >

Y at - it anyway how to print emptyElement as < emptyElement > < / emptyElement > rather than < emptyElement / >?

Thanks for any help.

Milos Nemec wrote:
Y at - it anyway how to print emptyElement as rather than ?

Is there a solution to your problem, you want to say?

Of course.

One obvious way is to post process. If the steps
1. Add the following

emptyElement.setTextContent ("REALLYEMPTYXXX");

2 produce the XML string
2. replacement of the wire to replace 'REALLYEMPTYXXX' "

Tags: Java

Similar Questions

  • How to select entire groups or to multiple recipients in MAIL, rather than one at a time?

    How to select entire groups or to multiple recipients in MAIL, rather than one at a time?

    One way is to use the app to create a group with the intended recipients. Then when composing the email just type the group name in the To: field.

  • How can I set my homepage to a new request tab rather than "suggested" or "white"?

    With the latest updates of Firefox, the tabs have changed. In the past, I was able to have a new tab open to my homepage (google), but seem to now have sites either empty or suggested/frequently visited. Although this sounds like a minor problem, he build a movement additional/click/selection and is a bit of your time and irritating - most of my use of the internet has its source in a research rather than a favorite site.
    Someone knows a way back?
    Thank you very much.
    R

    The preference of browser.newtab.url has been added to Firefox 13. Over the years, he was repeatedly attacked by malware. From Firefox 41, the preference can be changed using an interface programming or, in simpler terms, an extension.

    For example, you can use this extension:

    https://addons.Mozilla.org/firefox/addon/new-tab-override/

    After installing the extension, you must use the Options page to set the new desired tab page (instead of use subject: config).

    Open the page modules using either:

    • CTRL + SHIFT + a (Mac: Cmd + shift + a)
    • "3-bar" menu button (or tools) > Add-ons

    In the left column, click Extensions. Then on the side right, find the new tab override and click the Options button. (See first screenshot attached).

    Depending on the size of your screen, you may need to scroll down to enter the address in the form. (See second screenshot attached). For example:

    • (Default) page thumbnails = > subject: newtab
    • Blank tab = > subject: empty
    • Built-in Firefox homepage = > topic: welcome
    • Any other page = > full URL of the page

    Then tab or click this form field and you can test using Ctrl + t.

    Success?

    Once you have set it as you wish, you can close the Add-ons page (or use the back button to return to the list of Extensions of this Options page).

  • How to download all the songs at once on itunes game rather than one by one?

    How can I download my iTunes correspondence library to a device at the same time rather than one song at a time or synchronize with a USB cable?

    It's the forum for iTunes for Maccategory, if you download via iTunes on a Mac?  Or "device" that is not a Mac?

    If this is on a Mac, iTunes, select the songs you want to download a list of songs, then right click on the selection and download.

  • How Iswitch my plan for a single payment for the year, rather than monthly?

    My subscription of the CC is to be renewed. I don't see how to change it for a plan with a payment rather than monthly. Where are these options and prices?

    I signed up for the plan of Ps and Lr.

    Hello

    You will need to contact support by calling/chat for this request.

    Contact the customer service

    * Be sure to stay connected with your Adobe ID before accessing the link above *.

    Kind regards

    Sheena

  • How to generate the xml tag empty when meets elements void inside

    Hi gurus,

    IAM facing a problem to generate the empty tag, here is my file that I'm generating now
    <HEADER>
        <MINISTRY_CODE>RPO</MINISTRY_CODE>
        <DEPARTMENT_CODE>000</DEPARTMENT_CODE>
        <ORDER_CODE>RPO000EPO11001002</ORDER_CODE>
        <EXTERNAL_SYSTEM_CODE>E</EXTERNAL_SYSTEM_CODE>
        <AMENDMENT_NUMBER>0</AMENDMENT_NUMBER>
        <VARIATION_NUMBER>0</VARIATION_NUMBER>
        <EXCEPTIONS>
          <EXCEPTION>
            <EXCEPTION_CODE>PO016</EXCEPTION_CODE>
            <EXCEPTION_LONG_DESC>PO cannot be created/amended successfully</EXCEPTION_LONG_DESC>
          </EXCEPTION>
        </EXCEPTIONS>
      </HEADER>
      <ITEMS>
        <ITEM>
          <LINE_NUMBER>1</LINE_NUMBER>
          <EXCEPTIONS>
            <EXCEPTION>
              <EXCEPTION_CODE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
              <EXCEPTION_LONG_DESC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
            </EXCEPTION>
          </EXCEPTIONS>
          <LOCATIONS>
            <LOCATION>
              <LINE_NUMBER>1</LINE_NUMBER>
              <EXCEPTIONS>
                <EXCEPTION>
                  <EXCEPTION_CODE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
                  <EXCEPTION_LONG_DESC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
                </EXCEPTION>
              </EXCEPTIONS>
              <DISTRIBUTIONS>
                <DISTRIBUTION>
                  <LINE_NUMBER>1</LINE_NUMBER>
                  <EXCEPTIONS>
                    <EXCEPTION>
                      <EXCEPTION_CODE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
                      <EXCEPTION_LONG_DESC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
                    </EXCEPTION>
                  </EXCEPTIONS>
                </DISTRIBUTION>
              </DISTRIBUTIONS>
            </LOCATION>
          </LOCATIONS>
        </ITEM>
      </ITEMS>
    </GEBIZ_ORDER_ACK>
    current I'm generating tags EXCEPTION even if it is null as
    < EXCEPTIONS >
    < EXCEPTION >
    < EXCEPTION_CODE xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: Nil = "true" / >
    < EXCEPTION_LONG_DESC xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: Nil = "true" / >
    < / EXCEPTION >
    < / EXCEPTIONS >
    but my requirement is them does not when the exception code is null and generate as
    < EXCEPTIONS / >

    This is sql that I use to generate the above said code let me know how can I control who
                       SELECT xmlserialize(document
                                  xmlelement("GEBIZ_ORDER_ACK"
                                  , xmlagg(
                                      xmlconcat(hdr, dtls)
                                    )
                                  )
                                  as clob indent size = 2
                                )
                       --  INTO lv_out
                         FROM (
                               SELECT xmlelement("HEADER"
                                           , xmlelement("MINISTRY_CODE", poh.ministry_code)
                                           , xmlelement("EXCEPTIONS"
                                                 , xmlelement("EXCEPTION"
                                                             , xmlelement("EXCEPTION_CODE"   --,NVL(poh.exception_code,'NULL')
                                                             , xmlattributes(
                                                               NVL2(poh.exception_code,null,'http://www.w3.org/2001/XMLSchema-instance') as "xmlns:xsi"
                                                             , NVL2(poh.exception_code,null,'true') as "xsi:nil"
                                                               )
                                                             ,poh.exception_code)
                                                             , xmlelement("EXCEPTION_LONG_DESC"
                                                             , xmlattributes(
                                                               NVL2(poh.exception_long_desc,null,'http://www.w3.org/2001/XMLSchema-instance') as "xmlns:xsi"
                                                             , NVL2(poh.exception_long_desc,null,'true') as "xsi:nil"
                                                               )
                                                             ,poh.exception_long_desc)
                                                             )
                                                       )
                                           ) hdr
                                     , xmlelement("ITEMS"
                                     , xmlagg(
                                              xmlelement("ITEM"
                                               ,xmlelement("LINE_NUMBER", v1.line_no)
                                               ,xmlelement("EXCEPTIONS"
                                                        , xmlelement("EXCEPTION"
                                                                    , xmlelement("EXCEPTION_CODE"    --,NVL(v1.exception_code,'NULL')
                                                                    , xmlattributes(
                                                                      NVL2(v1.exception_code,null,'http://www.w3.org/2001/XMLSchema-instance') as "xmlns:xsi"
                                                                    , NVL2(v1.exception_code,null,'true') as "xsi:nil"
                                                                      )
                                                                    , v1.exception_code)
                                                                    , xmlelement("EXCEPTION_LONG_DESC"
                                                                    , xmlattributes(
                                                                      NVL2(v1.exception_long_desc,null,'http://www.w3.org/2001/XMLSchema-instance') as "xmlns:xsi"
                                                                    , NVL2(v1.exception_long_desc,null,'true') as "xsi:nil"
                                                                      )
                                                                    ,v1.exception_long_desc)
                                                                    )
                                                          )
                                               ,xmlelement("LOCATIONS"
                                               ,( SELECT xmlagg(
                                                          xmlelement("LOCATION"
                                                        , xmlelement("LINE_NUMBER",v2.location_line_no)
                                                        , xmlelement("EXCEPTIONS"
                                                        , xmlelement("EXCEPTION"
                                                        , xmlelement("EXCEPTION_CODE"   --,NVL(v2.exception_code,'NULL')
                                                        , xmlattributes(
                                                          NVL2(v2.exception_code,null,'http://www.w3.org/2001/XMLSchema-instance') as "xmlns:xsi"
                                                        , NVL2(v2.exception_code,null,'true') as "xsi:nil"
                                                          )
                                                        , v2.exception_code)
                                                        , xmlelement("EXCEPTION_LONG_DESC"
                                                        , xmlattributes(
                                                          NVL2(v2.exception_long_desc,null,'http://www.w3.org/2001/XMLSchema-instance') as "xmlns:xsi"
                                                        , NVL2(v2.exception_long_desc,null,'true') as "xsi:nil"
                                                          )
                                                        ,v2.exception_long_desc)
                                                                    )
                                                          )
                                               ,xmlelement("DISTRIBUTIONS"
                                               ,(SELECT xmlagg
                                                 (       xmlelement("DISTRIBUTION"
                                                         ,xmlelement("LINE_NUMBER", v3.distribution_line_no)
                                                         ,xmlelement("EXCEPTIONS"
                                                         , xmlelement("EXCEPTION"
                                                         , xmlelement("EXCEPTION_CODE"--,NVL(v3.exception_code,'NULL')
                                                         , xmlattributes(
                                                           NVL2(v3.exception_code,null,'http://www.w3.org/2001/XMLSchema-instance') as "xmlns:xsi"
                                                         , NVL2(v3.exception_code,null,'true') as "xsi:nil"
                                                          )
                                                         ,v3.exception_code)
                                                         , xmlelement("EXCEPTION_LONG_DESC"
                                                         , xmlattributes(
                                                           NVL2(v3.exception_long_desc,null,'http://www.w3.org/2001/XMLSchema-instance') as "xmlns:xsi"
                                                         , NVL2(v3.exception_long_desc,null,'true') as "xsi:nil"
                                                          )
                                                        ,v3.exception_long_desc)
                                                                    )
                                                            )
                                                          ) ORDER BY v3.distribution_line_no
                                                       ) FROM xgbz_fin_stage_ack_pot_v@dev_1157.RP.EDU.SG v3
                                                        WHERE v2.po_cont_code = v3.po_cont_code
                                                          AND v2.line_no = v3.line_no
                                                          AND v2.location_line_no = v3.location_line_no
                                                          AND v2.fs_timestamp = v3.fs_timestamp
                                                          AND v3.tx_timestamp IS  NULL
                                                     )
                                                   )
                                                 ) ORDER BY v2.location_line_no
                                              ) FROM xgbz_fin_stage_ack_pol_v@dev_1157.RP.EDU.SG v2
                                               WHERE v2.line_no = v1.line_no
                                                 AND v2.po_cont_code = v1.po_cont_code
                                                 AND v2.fs_timestamp = v1.fs_timestamp
                                                 AND v2.TX_TIMESTAMP IS NULL
                                 )
                               )
                             ) ORDER BY v1.line_no
                           )
                         ) dtls
                    FROM xgbz_fin_stage_ack_poh_v@dev_1157.rp.edu.sg poh,
                         xgbz_fin_stage_ack_pod_v@dev_1157.rp.edu.sg v1
                   WHERE v1.po_cont_code = poh.po_cont_code
                     AND v1.fs_timestamp = poh.fs_timestamp
                     AND v1.tx_timestamp IS NULL
                     AND poh.tx_timestamp IS NULL
                     AND poh.po_cont_code = rec_po_ack.po_cont_code
                   GROUP BY poh.po_cont_code,poh.ext_system_code,poh.amendment_no,poh.variation_no,poh.exception_code,poh.exception_long_desc,
                            poh.ministry_code, poh.dept_code)
    It's urgent please help in this regard.

    Thanks in advance.

    Concerning
    Mr. Nagendra

    Hello

    Here are two possible solutions:

    xmlelement("EXCEPTIONS",
      xmlforest(
        xmlforest(
          v1.exception_code as "EXCEPTION_CODE"
        , v1.exception_long_desc as "EXCEPTION_LONG_DESC"
        ) as "EXCEPTION"
      )
    )
    

    Mun

    xmlelement("EXCEPTIONS",
      case when v1.exception_code is not null
             or v1.exception_long_desc is not null
        then xmlelement("EXCEPTION",
               xmlforest(
                 v1.exception_code as "EXCEPTION_CODE"
               , v1.exception_long_desc as "EXCEPTION_LONG_DESC"
               )
             )
      end
    )
    
  • How to get several xml elements in a relationship 1: n without using xmlaggregation

    I need to create the following xml structure from an oracle database

    where each survey can multiple deelnemers (participants)

    I'm not sure create this use of XMLElement without getting the message "ORA-01427 subquery returns more then one line."

    I could try to use dbms_xmldom (never done that before) but I wonder if anyone knows how to generate this just using the plain Oracle SQL-XMLfunctions (XMLElement, XMLAggr)

    < NieuweSurveys >

    < survey >

    < Surveynaam > 2013 - 02 - 01 < / Surveynaam >

    < Months > 2013 - 02 - 01 < / months >

    < Einddatum > 2013 - 02 - 15 < / Einddatum >

    < Deelnemer >

    Tilde < Chairwoman > < / Chairwoman >

    < Tussenvoegsel / >

    DeelnemerA < Achternaam > < / Achternaam >

    man < Geslacht > < / Geslacht >

    < Emailadres > [email protected] < / Emailadres >

    < Voorkeurstaal > nl < / Voorkeurstaal >

    Schouten < account > & Nelisen < / account >

    bouwer < function > < / function >

    < / Deelnemer >

    < Deelnemer >

    Tilde < Chairwoman > < / Chairwoman >

    < Tussenvoegsel / >

    DeelnemerB < Achternaam > < / Achternaam >

    Vrouw < Geslacht > < / Geslacht >

    < Emailadres > [email protected] < / Emailadres >

    < Voorkeurstaal > nl < / Voorkeurstaal >

    Schouten < account > & Nelisen < / account >

    Tester of < function > < / function >

    < / Deelnemer >

    < / inquiry >

    < / NieuweSurveys >

    What is your version of the database? (SELECT * FROM version$ v)

    The query does not match the output that you claim that it produces.

    In any case, the problem is the following:

    ) as "deelnemers.

    Put an alias here should not generate an element - unless you are using XMLForest in your actual query without your telling us.

    That's why I ask about the version of db, it could be an old bug that's been fixed now (I have not to reproduce the behavior on 11.2).

    What happens when you delete the alias?

  • How to force short for element empty?

    Hello

    I want to Crete with most XML data stored in attributes:
    SQL*Plus: Release 11.2.0.1.0 Production on Do Dez 20 10:18:43 2012
    
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    
    Verbunden mit:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, Automatic Storage Management and OLAP options
    SQL> WITH my_data AS
      2         (SELECT 'test1' AS element_name
      3               , 0 AS tag_attrib
      4            FROM DUAL
      5          UNION ALL
      6          SELECT 'test2' AS element_name
      7               , 1 AS tag_attrib
      8            FROM DUAL)
      9  SELECT XMLELEMENT( element_name )
     10       , XMLELEMENT( element_name
     11                   , xmlattributes( tag_attrib as "tag_attrib" )
     12                    )
     13    FROM my_data;
    
    XMLELEMENT(ELEMENT_NAME)
    --------------------------------------------------------------------
    XMLELEMENT(ELEMENT_NAME,XMLATTRIBUTES(TAG_ATTRIBAS"TAG_ATTRIB"))
    --------------------------------------------------------------------
    <ELEMENT_NAME></ELEMENT_NAME>
    <ELEMENT_NAME tag_attrib="0"></ELEMENT_NAME>
    
    <ELEMENT_NAME></ELEMENT_NAME>
    <ELEMENT_NAME tag_attrib="1"></ELEMENT_NAME>
    How can I force the result like this beeing:
    XMLELEMENT(ELEMENT_NAME)
    --------------------------------------------------------------------
    XMLELEMENT(ELEMENT_NAME,XMLATTRIBUTES(TAG_ATTRIBAS"TAG_ATTRIB"))
    --------------------------------------------------------------------
    <ELEMENT_NAME/>
    <ELEMENT_NAME tag_attrib="0"/>
    
    <ELEMENT_NAME/>
    <ELEMENT_NAME tag_attrib="1"/>
    Good bye
    DPT

    Hello

    With items like this is controlled via serialization options.

    11.2, you can use XMLSerialize function with option INDENT:

    SQL> WITH my_data(element_name, tag_attrib) AS (
      2    SELECT 'test1', 0 FROM DUAL UNION ALL
      3    SELECT 'test2', 1 FROM DUAL
      4  )
      5  SELECT XMLSerialize(document
      6           XMLElement( element_name
      7           , XMLAttributes(tag_attrib as "tag_attrib")
      8           )
      9           indent size = 0
     10         )
     11  FROM my_data;
    
    XMLSERIALIZE(DOCUMENTXMLELEMEN
    --------------------------------------------------------------------------------
    
    
     
    

    The function serialize as default CLOB.
    You can specify VARCHAR2 or too much BLOB.

    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e23094/xdb13gen.htm#ADXDB5033

  • How to put an xml element in the header field?

    Hello friends,
    My requirement is like I have a particular item that should be printed on the header filed
    for ex - dept_no and dept_name in header field... Please let me know how...
    Thank you

    Use for-each@section:DEPT_GROUP
    and place the field directly in the header section.

    This would ensure that the dept value is reset for each group.

  • How to divide two xml elements to display

    I can give something like
    <? ele1? > div <? ele2? >
    to get the value of division of these two columns
    Thank you

    You must use it as

  • How to fix the toolbar if the bottom of the screen rather than side

    My children will install my toolbar to the right of my screen and I can't bring it back. It is not locked.  More therer are two icons for everything.  I can understand how to fix it.

    Hello

    Do you mean the taskbar at the bottom of the desktop computer or the Internet Explorer toolbar?

    Method 1:
    I suggest you to check if you are able to move the taskbar in the clean boot state.
    http://support.Microsoft.com/kb/929135
    Note:
    when the diagnostic is complete do not forget to reset the computer to a normal startup. Follow step 7 in the above article.

    Method 2:
    I suggest you to run the system restore before the changes.
    You can check the link:
    http://Windows.Microsoft.com/en-us/Windows7/products/features/system-restore

    Method 3:

    If the problem persists suggest you check with a new user account because this can happen due to the damaged user account,

    Create a user account:
    http://Windows.Microsoft.com/en-us/Windows7/create-a-user-account
    Note: If the problem does not occur after you create a new user account, and then try the steps in the following article to fix the damaged user account.
    Fix a corrupted user profile:
    http://Windows.Microsoft.com/en-us/Windows7/fix-a-corrupted-user-profile

  • How to configure we draw like the paths of the race, rather than the default of transparent traces?

    When I move a drawing creation using simple 1 black lines smooth to draw Adobe Illustrator CC, it is expanded or compound paths.  I want to be able to draw the image as a single path only (points in the middle of the race as opposed to control points on both sides of control shape with filling in the middle).  Is this possible?  Or is it possible to convert simple traced complex traces in Illustrator?

    Yes. Sue's right.

    With the help of Illustrator draw give you paths as the form of the task.  If you draw on the same layer, you'll find yourself with forms that are unique, but without the path to the Center.

    It does not appear that Adobe draw currently records the path of the finger/stylus, so any form you create in one movement appears as a single color.  (All by converting some isolated shots that are not recursive might be easy, strokes that create irregular shapes is not)

    OTOH, if you use something like Adobe's sketch, pouvez get you the paths, but in doing so, you can confiscate the brushes that you created in the application.  I have not sat down to figure out how to reproduce these brushes in Illustrator or Photoshop (easier).

    This is an Adobe Sketch illustration, sent to Illustrator and the embarrassing tildes I did to create.

    While you can open the path data by converting it, you can keep a double layer of your works of art first.  The conversion process will replace bitmaps by default brush strokes.

  • How can I force Firefox to access an external web site rather than the site corresponding to the cache on my computer?

    A web site that I regularly access using Firefox has been updated in the last 24 hours. I make Firefox to access the external site updates rather than site updates apparently stored on my memory cache?

    You can reload webpages and ignore the cache to refresh potentially stale or corrupt.

    • Hold down the SHIFT key and click the Reload button
    • Press 'Ctrl + F5' or 'Ctrl + Shift + R' (Windows, Linux)
    • Press 'Command + shift + R' (Mac)
  • How to the mozilla help page search engine AND my terms rather than OR them?

    Example: Search for 'failure of the log message timestamp' results with just the personal conditions. I tried ANDing them and surrounding quotation marks without success. I tried 'advanced search' without success.

    It is on the 'doing' list for the site, but currently, your best bet is to do a targeted search of Google. In other words:

    https://www.Google.com/search?q=message+log+timestamp+failure+site:support.Mozilla.com

    P.S. There is an advanced search, but it has the same problem.

  • In the mailbox sent how can I change to show to whom it was sent rather than have it show me that he was sent by because it's always me?

    In the sent mailbox headers are subject - from - Date. I want to show him the subject - To - Date. This would allow me to analyze my messages sent for a message that I sent to someone. Now it shows since then and it is of course my email address I already knew.

    Can you not change the columns in this window and use the recipient instead of go? There should be a small button at the end of the column headers.

Maybe you are looking for