convert postgresql table to xml - postgresql

I have a postgresql table with following columns
classificazione_dpr_412,superficie_utile_riscaldata, classe_energetica, epgl_n_ren, tipo_intervento_1, tipo_intervento_2, tipo_intervento_3, superficie_disperdente, rapporto_asol_asup, tipo_impianto, anno_installazione_generatore, combustibile, potenza_nominale, efficienza_media_stagionale, ep_nren_clim_inv, ep_nren_acs, ep_nren_illuminazione, comune, regione, ep_nren_standard_rif
and need a postgresql query to transform it into following xml file.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ape2015 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<datiGenerali>
<classificazioneDPR412>"classificazione_dpr_412"</classificazioneDPR412>
<datiIdentificativi>
<superficieUtileRiscaldata> "superficie_utile_riscaldata"</superficieUtileRiscaldata>
</datiIdentificativi>
</datiGenerali>
<prestazioneGlobale>
<prestazioneEnergeticaGlobale>
<classificazione>
<classeEnergetica>"classe_energetica"</classeEnergetica>
<epglnren> "epgl_n_ren"</epglnren>
</classificazione>
</prestazioneEnergeticaGlobale>
</prestazioneGlobale>
<raccomandazioni>
<interventoRaccomandato>
<codice>"tipo_intervento_1"</codice>
<tipoInterventoRaccomandato>"tipo_intervento_1"</tipoInterventoRaccomandato>
</interventoRaccomandato>
<interventoRaccomandato>
<codice>"tipo_intervento_2"</codice>
<tipoInterventoRaccomandato>"tipo_intervento_2"</tipoInterventoRaccomandato>
</interventoRaccomandato>
<interventoRaccomandato>
<codice>"tipo_intervento_3"</codice>
<tipoInterventoRaccomandato>"tipo_intervento_3"</tipoInterventoRaccomandato>
</interventoRaccomandato>
</raccomandazioni>
<datiFabbricato>
<superficieDisperdente> "superficie_disperdente"</superficieDisperdente>
<rapportoAsolAsupUtile> "rapporto_asol_asup"</rapportoAsolAsupUtile>
</datiFabbricato>
<datiImpianti>
<climatizzazioneInvernale>
<impianto>
<tipoImpianto>"tipo_impianto"</tipoImpianto>
<annoInstallazione>"anno_installazione_generatore"</annoInstallazione>
<vettoriEnergeticiUtilizzati>
<vettore>"combustibile"</vettore>
</vettoriEnergeticiUtilizzati>
<potenzaNominale> "potenza_nominale"</potenzaNominale>
</impianto>
<efficienza> "efficienza_media_stagionale"</efficienza>
<prestazione>
<epnren> "ep_nren_clim_inv"</epnren>
</prestazione>
</climatizzazioneInvernale>
<produzioneACS>
<prestazione>
<epnren> "ep_nren_acs"</epnren>
</prestazione>
</produzioneACS>
<illuminazione>
<prestazione>
<epnren> "ep_nren_illuminazione"</epnren>
</prestazione>
</illuminazione>
</datiImpianti>
<datiExtra>
<comune>"comune"</comune>
<regione>"regione"</regione>
<EPglnrenRifStandard> "ep_nren_standard_rif"</EPglnrenRifStandard>
</datiExtra>
</ape2015>
I need a proper postgresql query to transform postgresql table into xml file.

If you are executing query directly in tools or console, you can use tools like DataGrip which will give you an option to export files in various options including XML.
If you are executing a query inside an application, it should be very easy to convert JSON or Object data to XML. You do not need SQL to convert data into XML file.

Related

pyspark does not parse an xml from a file containing multiple xmls

I am using spark 2.3.2 with python 3.7 to parse xml.
In an xml file (sample), I have appended 2 xmls.
When I parse it with:
os.environ['PYSPARK_SUBMIT_ARGS'] = '--packages com.databricks:spark-xml_2.11:0.7.0 pyspark-shell'
conf = pyspark.SparkConf()
sc = SparkSession.builder.config(conf=conf).getOrCreate()
spark = SQLContext(sc)
dfSample = (spark.read.format("xml").option("rowTag", "xocs:doc")
.load(r"sample.xml"))
I see 2 xmls' data:
However, what I need is to extract the info under "ref-info" tag (along with their corresponding key eids), so my code is:
(dfSample.
withColumn("metaExp", F.explode(F.array("xocs:meta"))).
withColumn("eid", F.col("metaExp.xocs:eid")).
select("eid","xocs:item").
withColumn("xocs:itemExp", F.explode(F.array("xocs:item"))).
withColumn("item", F.col("xocs:itemExp.item")).
withColumn("itemExp", F.explode(F.array("item"))).
withColumn("bibrecord", F.col("item.bibrecord")).
withColumn("bibrecordExp", F.explode(F.array("bibrecord"))).
withColumn("tail", F.col("bibrecord.tail")).
withColumn("tailExp", F.explode(F.array("tail"))).
withColumn("bibliography", F.col("tail.bibliography")).
withColumn("bibliographyExp", F.explode(F.array("bibliography"))).
withColumn("reference", F.col("bibliography.reference")).
withColumn("referenceExp", F.explode(F.array("reference"))).
withColumn("ref-infoExp", F.explode(F.col("reference.ref-info"))).
withColumn("authors", F.explode(F.col("ref-infoExp.ref-authors.author"))).
withColumn("py", (F.col("ref-infoExp.ref-publicationyear._first"))).
withColumn("so", (F.col("ref-infoExp.ref-sourcetitle"))).
withColumn("ti", (F.col("ref-infoExp.ref-title"))).
drop("xocs:item", "xocs:itemExp", "item", "itemExp", "bibrecord", "bibrecordExp", "tail", "tailExp", "bibliography",
"bibliographyExp", "reference", "referenceExp").show())
This extracts the info only from the xml with eid = 85082880163
When I delete this one and only kept the one with eid = 85082880158, it works.
My file is an xml file containing those 2 lines in the link. I have also tried to merge those 2 into one xml but could not manage.
What is wrong with my data/approach? (My ultimate plan is to create such a file containing thousands of different xmls to be parsed)
Your trouble lies in this piece of XML:
<xocs:item>
<item>
<bibrecord>
<head>
<abstracts>
<abstract original="y" xml:lang="eng">
<ce:para>
Apple is often affected by [...] intercellular CO <inf>2</inf> concentration [...]
^^^^^^^^^^^^
While it is correct XML (mixed content), this embedded tag <inf>2</inf> seems to be breaking spark-xml parser. If you remove it (or convert to corresponding HTML entities) you will get correct results.

Play Framework 2.x Can not output raw url in view

I'm trying to output the following raw url in the view.
https://loopme.me/api/vast/ads?appId=e18c19fa43&vast=2&uid=1234&ip=8.8.8.8&bundleid=com.loopme&appname=my_talking_pet&sdk=16.2&exchange=admarvel
however, even if I wrap the dynamic content with #Html method, the output is always
https://loopme.me/api/vast/ads?appId=e18c19fa43&vast=2&uid=1234&ip=8.8.8.8&bundleid=com.loopme&appname=my_talking_pet&sdk=16.2&exchange=admarvel
that is to say, '&' is still escaped.
Can anyone help me to correctly output raw contents in the view? I'm using scala bases template engine.
code:
<vmap:VMAP xmlns:vmap="http://www.iab.net/videosuite/vmap" version="1.0">
#for(offset <- timeOffsets){
<vmap:AdBreak breakType="linear" breakId="#offset.id"
timeOffset="#timeOffset(offset)">
#for(campaign <- campaigns){
<vmap:AdSource allowMultipleAds="allowMultipleAds"
followRedirects="true" id="#campaign.id">
<AdTagURI templateType="vast3">
<![CDATA[
#Html(campaign.extTag)
]]>
</AdTagURI>
</vmap:AdSource>
}
<vmap:TrackingEvents>
<vmap:Tracking event="breakStart">
http://MyServer.com/breakstart.gif
</vmap:Tracking>
</vmap:TrackingEvents>
</vmap:AdBreak>
}
</vmap:VMAP>
In a HTML template
import play.twirl.api.HtmlFormat
HtmlFormat.raw(yourURL)
In a XML template
import play.twirl.api.XmlFormat
XmlFormat.raw(yourURL)

XML Mapper issue in Mybatis

nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
this is the syntax
it working well while fetching the result in ORACLE SQL DEVELOPER
but while start my local server it gives error
please suggest what need to fix on this
SQL is good and working to get records directly from DB
select
rownum test,
os_alternate_label "altlabel",
em_customs_bar_code "label",
em_source_appl "source",
'H5' "altoutcome",
DECODE(OS_NL_DO_NOT_LOAD,1,'NL',
DECODE(OS_H5_ALT_DUP_HOLD,1,'H5',
DECODE(OS_BD_RTS_EC,1,'BD',
DECODE(OS_H2_EC_HOLD,1,'H2',
DECODE(OS_HD_NO_DISP_HOLD,1,'HD',
DECODE(OS_H3_CBP_HOLD,1,'H3',
DECODE(OS_H4_USPIS_HOLD,1,'H4',
DECODE(OS_UD_RTS_CUSTOMER,1,'UD',
DECODE(OS_NQ_EU_WAIT_TIME,1,'NQ',
DECODE(OS_H1_iPASS_HOLD,1,'H1',
DECODE(OS_DG_DANGER_HOLD,1,'DG',
DECODE(OS_CC_COMM_HOLD,1,'CC',
DECODE(OS_H6_CUS_DUP_HOLD,1,'H6',
DECODE(OS_RL_RELEASE,1,'RL','XX')))))))))))))) "customoutcome",
em_destination_country "destCo",
em_recipient_last_name "tolastName",
em_recipient_business "tobusinessname",
em_recipient_address "toaddress",
em_recipient_city "tocity",
em_recipient_state "toregionprov",
em_recipient_postcode "postcode",
to_char(em_date_time_received,'MM/DD/YY HH24:MI') "timeReceived"
FROM CUSTOMS.OUTCOME_STATUS_T,
CUSTOMS.ECM_MANIFEST_T
WHERE OS_CUSTOMS_BAR_CODE = EM_CUSTOMS_BAR_CODE
Use escape character I believe the '/' used to define date is causing problem
<![CDATA[
select
rownum test,
os_alternate_label "altlabel",
em_customs_bar_code "label",
em_source_appl "source",
'H5' "altoutcome",
DECODE(OS_NL_DO_NOT_LOAD,1,'NL',
DECODE(OS_H5_ALT_DUP_HOLD,1,'H5',
DECODE(OS_BD_RTS_EC,1,'BD',
DECODE(OS_H2_EC_HOLD,1,'H2',
DECODE(OS_HD_NO_DISP_HOLD,1,'HD',
DECODE(OS_H3_CBP_HOLD,1,'H3',
DECODE(OS_H4_USPIS_HOLD,1,'H4',
DECODE(OS_UD_RTS_CUSTOMER,1,'UD',
DECODE(OS_NQ_EU_WAIT_TIME,1,'NQ',
DECODE(OS_H1_iPASS_HOLD,1,'H1',
DECODE(OS_DG_DANGER_HOLD,1,'DG',
DECODE(OS_CC_COMM_HOLD,1,'CC',
DECODE(OS_H6_CUS_DUP_HOLD,1,'H6',
DECODE(OS_RL_RELEASE,1,'RL','XX')))))))))))))) "customoutcome",
em_destination_country "destCo",
em_recipient_last_name "tolastName",
em_recipient_business "tobusinessname",
em_recipient_address "toaddress",
em_recipient_city "tocity",
em_recipient_state "toregionprov",
em_recipient_postcode "postcode",
to_char(em_date_time_received,'MM/DD/YY HH24:MI') "timeReceived"
FROM CUSTOMS.OUTCOME_STATUS_T,
CUSTOMS.ECM_MANIFEST_T
WHERE OS_CUSTOMS_BAR_CODE = EM_CUSTOMS_BAR_CODE
]]>

ibec_ExtractMetadata don't extract tables like "TaSomeData". IBExpert. IBEScript Firebird 2.1

I have a problem with the command ibec_ExtractMetadata from IBEScript(ibeblock). In my Database most tables have names in InfixCaps like "TaActions", "TaDiscountSystem" etc.
If I use ibec_ExtractMetadata with tables in UpperCase - all is well:
ibec_ExtractMetadata(OtdelDB, 'd:\DC_Otdel.sql',
'Domains=NONE; Tables=ACCESSGROUPS; Views=NONE; Triggers=NONE;
Procedures=NONE; Generators=NONE;
Exceptions=NONE; UDFs=NONE; Roles=NONE;DataTables=ACCESSGROUPS;
ExtractBLOBs;UseReinsert; CommitAfter=1000', cbb);
But if I want to extract metadata from table "TaDiscountSystem":
ibec_ExtractMetadata(OtdelDB, 'd:\DC_Otdel.sql',
'AlwaysQuoteIdents; Domains=NONE; Tables=NONE; Views=NONE; Triggers=NONE;
Procedures=NONE; Generators=NONE;
Exceptions=NONE; UDFs=NONE; Roles=NONE;DataTables=TalmbDiscountSystem;
ExtractBLOBs; UseReinsert; CommitAfter=1000', cbb);
The script output is empty.

Create a tree using XML in SmartGWT

I have an XML in the format :
<RootNode name="Tree">
<ChildNode name="ChildNode1">
<LeafNode name="Leaf">Leaf1</LeafNode>
<LeafNode>Leaf2</LeafNode>
<ChildNode name="ChildNode1.1">
<LeafNode>Leaf1.1</LeafNode>
<LeafNode>Leaf1.2</LeafNode>
<LeafNode>Leaf1.3</LeafNode>
</ChildNode>
</ChildNode>
<ChildNode name="ChildNode2">
<LeafNode>Leaf3</LeafNode>
<LeafNode>Leaf3</LeafNode>
</ChildNode>
<ChildNode name="ChildNode3">
</ChildNode>
</RootNode>
How do i convert it to a tree using SmartGWT?