Home » Developer & Programmer » JDeveloper, Java & XML » How do I stop xmlquery from changing encoding? (Oracle 19c)
How do I stop xmlquery from changing encoding? [message #683243] Fri, 18 December 2020 08:40
Buchas
Messages: 101
Registered: March 2006
Senior Member
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?
Previous Topic: Unable to connect to Oracle with JDBC
Next Topic: Java Access Bridge events > .NET 4.5
Goto Forum:
  


Current Time: Wed Oct 20 15:19:32 CDT 2021