Question

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.

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top