The Requested output is should be as follows:
<Consignment id="123" date="2017-06-08">
<Box id="321" />
</Consignment>
where the <box> tag should be self-closing as above.
I am using the following code:
SELECT XMLELEMENT( "Consignment", XMLATTRIBUTES('123' AS "id",sysdate AS "date" ),
XMLELEMENT( "Box", xmlattributes( '321' as "id" ))
).getstringval() as xxx FROM DUAL;
but it always return the following results (where the tag <box> has a separated closing tag </box>):
<Consignment id="123" date="2017-06-08">
<Box id="321"></Box>
</Consignment>
how to get the above <box> tag self-closed?
If you only need to do this with "box", then you can use :
If you have other tags that need to be processed this way, you will need to use REGEXP_REPLACE using the same logic.
Semantically though, both forms represent the exact same data, which is why you can't do what you want to do "easily" with some parameter given to the XML generator (and why maybe you should not do that in the first place!).