Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

XML within a column - need to parse

Hi
I am trying to find some resources that will assist in parsing some XML that I have in a QVD. Can anyone help?

Attached is the XML that is contained within 1 cell, and I am trying to query it within QlikSense

Have tried loading the XML into a separate XML file;

RatingData:

Load

*

FROM [Policy.QVD] (qvd);

Store RatingData INTO RatingData.XML ;

But as you can see from below, the QlikSense load does not pick up the XML and create the tables;

LOAD

     String%Table,

     %Key_QvdFieldHeader_59D66ED49CFF179D

FROM [lib://Qlik Files/Extract\Peak\TWGInsurance_ForSFTP\Policy.QVD]

(XmlSimple, table is [QvdTableHeader/Fields/QvdFieldHeader/Tags/String]);

LOAD

     "FieldName",

     BitOffset,

    BitWidth,

     Bias,

     NoOfSymbols,

     Offset,

     "Length",

     "NumberFormat/Type",

     "NumberFormat/nDec",

     "NumberFormat/UseThou",

     "NumberFormat/Dec",

     "NumberFormat/Thou",

     %Key_QvdTableHeader_B94FCCAC68ED3E20,

     %Key_QvdFieldHeader_59D66ED49CFF179D

FROM RatingData.XML

(XmlSimple, table is [QvdTableHeader/Fields/QvdFieldHeader]);

LOAD

     QvBuildNo,

     CreatorDoc,

     CreateUtcTime,

     SourceFileSize,

     "TableName",

     RecordByteSize,

     NoOfRecords,

     Offset,

     "Length",

     "Lineage/LineageInfo/Discriminator",

     "Lineage/LineageInfo/Statement",

     %Key_QvdTableHeader_B94FCCAC68ED3E20

FROM RatingData.XML

(XmlSimple, table is QvdTableHeader);

Would really welcome some assistance please?

1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

I think

   LOAD

    .....

    .......... table is [RatingData]);

needs to be changed to

  LOAD

      [CPI RA],

      AOI,

      AV,

      CV,

      V,

      R,

      C,

      I,   

      Id

    From_Field('DataTable','RD') (xmlSimple, table is [RatingData/CP]);

View solution in original post

7 Replies
petter
Partner - Champion III
Partner - Champion III

By making use of the a load statements FROM_FIELD instead of FROM, RESIDENT etc you can read data from an existing resident field as if  the data in the field came from a file. Each and every single value would be treated like a single file from the file system. This also means that you can have the same format specifications  of the "file" and specify that it is in XML format like with (XMLSimple, table is [vechicles/cars]).


It doesn't seem to be very fast - but if you understand that each and every single value represents a separate "file" a 1000 rows with a single column/field of XML would be interpreted by using FROM_FIELD as 1000 separate XML-files. They would of course be auto concatenated so one could believe that they might be like separate rows in a file - but they are not.

petter
Partner - Champion III
Partner - Champion III

Here is a simple example - I have used INLINE just to make it easier to read, but you might have the source file coming from a file by using FROM or of course also from a database by having a following SQL statement.


DATA: LOAD * INLINE `

# , XML , CSV

1, "<note>

  <title>Strong and Brave</title>

    <body>

      This article is about a young woman, a little puppy and their journey

    </body>

  </note>

", "A;B;C;D

1;2;3;4

5;6;7;8"

` (txt,msq);


NOTES:

LOAD

  title,

  body

FROM_FIELD (DATA,XML) (xmlSimple, table is [note]);


FROM_CSV:

LOAD

  *

FROM_FIELD(DATA,CSV) (txt, delimiter is ';', embedded labels);

So in this example we have a mixed format file with the top level content in regular CSV with commas as separators and two sub-formats of XML and CSV with semicolon as delimiter.

Anonymous
Not applicable
Author

Hi Petter,

Thank you for your response. I am, however, having some issues.....

This is the loads that I am using;

Policy:

LOAD

    ContractId,

    RatingData

   

FROM Policy.QVD;


Premiums:

Load

PExIPT,

CDExIPT,

CP


From_Field (Policy,RatingData) (xmlSimple,table is [Policies]);


Contract ID is the unique identifier within the QVD, and RatingData contains the XML that was previously attached, but I am getting 0 returns.

If we pull the values within the RatingData field we have;

<RatingData RId="48fbf828-055e-41a1-a74d-50ec5e6b3bcf" HBR="false" PBR="1.0000" IPTR="0" VATR="0" HOIPTR="false" PExIPT="276.82" PIncIPT="310.04" AncExT="0" AncTax="0" MTAAExcIPT="0" MTAAncTax="0" CanAExcIPT="0" CanAncTax="0" NbChIncIpt="30.0000" RnwlChIncIpt="0" MTADIncIPT="0" MTADExIPT="0" MTACIncIPT="0" MTAPIncIPT="0" MTAPExIPT="0" MTAFPd="0" MTAPPd="0" MTAPrM="0" CDIncIPT="0" CDExIPT="0" CPIncIPT="0" CPExIPT="0" CC="0" CTInIpt="0" CTIpt="0" CTapp="0" CFPD="0" CPPD="0" CPRM="0" BCP="0.46500000" PExcCExcIpt="148.10" PExcCIncIpt="165.87" Psp="0"><CP><CPI Id="3" I="false" C="RSAA" R="0.53500000" V="148.10" AV="0" AOI="-1"/><CPI Id="2" I="true" C="TWG" R="0.46500000" V="128.72" AV="0" AOI="-1"/></CP><C/><RatingItems/><LP><LPItems RId="1f316f4b-89a7-462c-b780-d557280f036b" HBR="false" PBR="1.0000" IPTR="0.1200" VATR="0" HOIPTR="false" PExIPT="276.82" PIncIPT="310.04" AncExT="0" AncTax="0" MTAAExcIPT="0" MTAAncTax="0" CanAExcIPT="0" CanAncTax="0" NbChIncIpt="0" RnwlChIncIpt="0" MTADIncIPT="0" MTADExIPT="0" MTACIncIPT="0" MTAPIncIPT="0" MTAPExIPT="0" MTAFPd="0" MTAPPd="0" MTAPrM="0" CDIncIPT="0" CDExIPT="0" CPIncIPT="0" CPExIPT="0" CC="0" CTInIpt="0" CTIpt="0" CTapp="0" CFPD="0" CPPD="0" CPRM="0" BCP="0.46500000" PExcCExcIpt="148.10" PExcCIncIpt="165.87"><CP/><C/><RatingItems><RI RId="13788" RVId="83022" K="LandlordsProperties[0].BuildingsHasAd" V="1" L="0.10000000" Alr="1.100000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="0" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13789" RVId="83024" K="LandlordsProperties[0].BuildingsAreaId" V="2" L="-0.14500000" Alr="0.94050000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="1" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13790" RVId="83050" K="LandlordsProperties[0].BuildingsPropertyAgeId" V="9" L="-0.07500000" Alr="0.8699625000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="2" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13792" RVId="83417" K="LandlordsProperties[0].BuildingsNumberOfBedrooms" V="3" L="0.00000000" Alr="0.8699625000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Add" O="4" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13793" RVId="83422" K="LandlordsProperties[0].BuildingsSIVsNumBeds" V="250000" L="-0.10000000" Alr="0.7829662500000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="5" LvId="83417" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13794" RVId="83056" K="LandlordsProperties[0].BuildingsPropertyTypeId" V="6" L="-0.02000000" Alr="0.7673069250000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="6" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13795" RVId="83076" K="LandlordsProperties[0].BuildingsExcessId" V="2" L="0.00000000" Alr="0.7673069250000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="7" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13796" RVId="83087" K="BuildingsNCDYears" V="6" L="-0.25000000" Alr="0.5754801937500000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="8" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13797" RVId="83089" K="BuildingsPolicyHolderAge" V="59" L="0.00000000" Alr="0.5754801937500000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="9" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13798" RVId="83093" K="LandlordsProperties[0].BuildingsWallConstructionId" V="5" L="0.00000000" Alr="0.5754801937500000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="10" LvId="-1" PrILl="13799" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13799" RVId="83148" K="LandlordsProperties[0].BuildingsConstructionDetails.LandlordsRoofConstructionId" V="23" L="0.00000000" Alr="0.5754801937500000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="11" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="true" Cs="false" PRId="-1"><En/></RI><RI RId="13802" RVId="83172" K="LandlordsProperties[0].BuildingsMinimumLoadingType" V="2" L="0.65000000" Alr="0.65000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Minimum" O="14" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13803" RVId="83166" K="BuildingsNumberOfProperties" V="1" L="0.00000000" Alr="0.6500000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="15" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13804" RVId="83481" K="LandlordsProperties[0].BuildingsHasMd" V="1" L="0.00000000" Alr="0.6500000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Add" O="16" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13805" RVId="83482" K="LandlordsProperties[0].BuildingsHasTheftCover" V="1" L="0.12000000" Alr="0.728000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="17" LvId="83481" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13806" RVId="83170" K="LandlordsProperties[0].BuildingsPolicyCoverType" V="2" L="0.00000000" Alr="0.728000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="18" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13807" RVId="83173" K="LandlordsProperties[0].BuildingsSumInsured" V="250" L="0.00000000" Alr="182.00000000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="AddThenMultiplyByValue" O="19" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13808" RVId="83174" K="LandlordsProperties[0].BuildingsBaseRateIds" V="2" L="-0.18626500" Alr="148.09977000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Multiply" O="20" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13810" RVId="83517" K="LandlordsProperties[0].BuildingsOccupationSumInsured" V="250000" L="0.00000000" Alr="148.09977000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Add" O="22" LvId="-1" PrILl="-1" Sec="Buildings" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13838" RVId="83330" K="LandlordsProperties[0].PropertyOccupationMinimumNumberOfUnoccupiedDays" V="0" L="0.00000000" Alr="148.09977000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Add" O="50" LvId="-1" PrILl="-1" Sec="" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13885" RVId="83381" K="LandlordsProperties[0].LandlordsManualNonStandardReferralValue" V="0" L="1.00000000" Alr="148.09977000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="AddThenMultiplyByValue" O="97" LvId="-1" PrILl="-1" Sec="" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13886" RVId="83382" K="LandlordsProperties[0].PremiumBeforeMinimumHook" V="1" L="0.00000000" Alr="148.09977000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Add" O="98" LvId="-1" PrILl="-1" Sec="" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13891" RVId="83336" K="LandlordsProperties[0].MinimumPremiumType" V="2" L="53.50000000" Alr="148.09977000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Minimum" O="103" LvId="-1" PrILl="-1" Sec="" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13892" RVId="83650" K="LandlordsProperties[0].LiabilityPolicyCoverTypeId" V="2" L="0.00000000" Alr="148.09977000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Add" O="104" LvId="-1" PrILl="-1" Sec="" Skipl="false" Cs="false" PRId="-1"><En/></RI><RI RId="13893" RVId="83651" K="LandlordsProperties[0].BuildingsLandlordsLiabilityId" V="2" L="0.00000000" Alr="148.09977000000000000000000000" S="Accept" Ao="false" OS="Accept" RT="New" RCO="Add" O="105" LvId="83650" PrILl="-1" Sec="" Skipl="false" Cs="false" PRId="-1"><En/></RI></RatingItems><Ancs/></LPItems></LP><Ancs/><PA><PAItems Id="237" AId="208" CPId="2" CM="GWPPercentage" CV="0.1800" V="49.83"/></PA></RatingData>

So you can see that it is in XML form.

If I write it directly on the SQL Server that the QVD is created from;

SELECT

P.ContractId

,P.RatingData.value('(RatingData/@PExIPT)[1]', 'MONEY')

,P.RatingData.value('(RatingData/@PIncIPT)[1]', 'MONEY') - P.RatingData.value('(RatingData/@PExIPT)[1]', 'MONEY')

,P.RatingData.value('(RatingData/CP/CPI[@I="true"]/@V)[1]', 'MONEY')

,P.AdminChargeValue

,P.RatingData.value('(RatingData/PA/PAItems/@V)[1]','MONEY')

These return the values.

I am just not getting the values from the load.

Anonymous
Not applicable
Author

So, I have something that works;

XMLOutput:

Load

PIncIPT

,PExIPT

,PExcCExcIpt


From_Field('DataTable','RD') (xmlSimple, table is [RatingData])


Which is great for pulling data from;


1.png

Thank you

However, how do you get to the data in;

2.png

petter
Partner - Champion III
Partner - Champion III

I think

   LOAD

    .....

    .......... table is [RatingData]);

needs to be changed to

  LOAD

      [CPI RA],

      AOI,

      AV,

      CV,

      V,

      R,

      C,

      I,   

      Id

    From_Field('DataTable','RD') (xmlSimple, table is [RatingData/CP]);

Anonymous
Not applicable
Author

Hi Petter,

Thank you for your help

In the end I did;

XMLOutput:

Load

RId as RatingJoin,

PIncIPT as [Premium Inc IPT],

PExIPT as [Premium Ex IPT],

PIncIPT - PExIPT as IPT

From_Field('Policy','RD') (xmlSimple, table is [RatingData])

CPOutput:

Load

peek(RD,1,RId) as RatingJoin,

I as [True/False],

V as [Comm],

Id as ID

From_Field ('Policy','RD') (xmlSimple, table is [RatingData/CP/CPI])

where I = 'true'

to get the information that I needed.

petter
Partner - Champion III
Partner - Champion III

You're welcome - happy to help