Hello,
My task is to add XML fragment into existing XML. I have a code, that does almost what I want:
with duom as (select xmltype('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:getMmGrupesResp xmlns:ns2="http://www.vmi.lt/mmr/mmgrupes">
<MMGrupes>
<MMGrupe>
<GRKodas>68</GRKodas>
<DataNuo>2020-07-20</DataNuo>
</MMGrupe>
<MMGrupe>
<GRKodas>84</GRKodas>
<DataNuo>2020-07-20</DataNuo>
</MMGrupe>
</MMGrupes>
</ns2:getMmGrupesResp>') input from dual)
select xmlquery('
declare namespace ns2 = "http://www.vmi.lt/mmr/mmgrupes";
copy $i := $p1 modify (
for $j in $i/ns2:getMmGrupesResp
return insert nodes $xml_mod as first into $j
)
return $i'
passing duom.input as "p1",
xmltype ('<JA>
<JAKodas>301182231</JAKodas>
<JAPavadinimas>Sodininkų bendrija "LK 034"</JAPavadinimas>
</JA>' ) as "xml_mod"
returning content) output
,duom.input
from duom
;
The output XML should result in fragment xml_mod added into ns2:getMmGrupesResp element as the first subelement.
The output looks like this:
<?xml version="1.0" encoding="ISO-8859-4" standalone="yes"?>
<ns2:getMmGrupesResp xmlns:ns2="http://www.vmi.lt/mmr/mmgrupes">
<JA>
<JAKodas>301182231</JAKodas>
<JAPavadinimas>Sodininkų bendrija "LK 034"</JAPavadinimas>
</JA>
<MMGrupes>
<MMGrupe>
<GRKodas>68</GRKodas>
<DataNuo>2020-07-20</DataNuo>
</MMGrupe>
<MMGrupe>
<GRKodas>84</GRKodas>
<DataNuo>2020-07-20</DataNuo>
</MMGrupe>
</MMGrupes>
</ns2:getMmGrupesResp>
The XML modification is fine, but the problem is that input has encoding="UTF-8", while output gets it changed to encoding="ISO-8859-4". I do not want to change encoding. How can I prevent encoding from changing?