简体   繁体   中英

How to close emty tag in XMLELEMENT?

Colls, hello. I can't close empty tag "password". There is my code:

select
XMLROOT(
        XMLELEMENT("prod",
                XMLELEMENT("prod2",
                           XMLELEMENT("quest",
                                      XMLELEMENT("request",
                                                  XMLELEMENT("OutputFormat", 'XML'),
                                                  XMLELEMENT("lang", 'ru'),
                                                       XMLELEMENT("RequestReq",
                                                                 XMLELEMENT("User", 'Мyya'),
                                                                 XMLELEMENT("Password", null)
                                                                 )


                                                )
                                      )
                          )
                  ),

         version '1.0" encoding="windows-1251')  as XML from dual;

If you run this code tag "password" will be opened :

<Password/>

But i need it closed like:

<Password></Password/>

So... could anybody help me to close "password" tag? I tried some cases with "replace" and "xmlattributes", but the problem is not solved yet.

I have added a value(a*1*c*3) to password and then replaced the value with null. You can add a value or set of characters which don't occur regularly to avoid any data issues

select
REPLACE((XMLROOT(
        XMLELEMENT("prod",
                XMLELEMENT("prod2",
                           XMLELEMENT("quest",
                                      XMLELEMENT("request",
                                                  XMLELEMENT("OutputFormat", 'XML'),
                                                  XMLELEMENT("lang", 'ru'),
                                                       XMLELEMENT("RequestReq",
                                                                 XMLELEMENT("User", 'Мyya1'),
                                                                 XMLELEMENT("Password",'a*1*c*3')
                                                                 )


                                                )
                                      )
                          )
                  ),

         version '1.0" encoding="windows-1251')),'a*1*c*3',null)  as XML from dual;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM