Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
FPouget1651761130
Contributor
Contributor

Counting true/false occurences on XML

Hi,

I need to count specifics occurences on XML ("true" or "false") and get the results in a table

I try using a tXMLMap but so far without success.

Any idea where I can lookinf for?

My XML:

<?xml version="1.0" encoding="UTF-8"?>

<customers>

<customer id="1">

<customerStatus vip="false" gold="false"/>

</customer>

<customer id="2">

<customerStatus vip="true" gold="false"/>

</customer>

<customer id="3">

<customerStatus vip="true" gold="true"/>

</customer>

</customers>

 

 

Wishes result:

| vip | gold|

| 2 | 1 |

Labels (3)
7 Replies
Anonymous
Not applicable

Hi

Using a tFileInputXML to read this XML file and extract vip and gold value, filter the 'true' value on tFilterRow and count it with tAggregateRow.

Please try and let me know if you have any questions.

 

Regards

Shong

FPouget1651761130
Contributor
Contributor
Author

Thanks I have a begin on something now 🙂

 

It works for the values "gold" and "vip" separately but how to count them together?

 

I tried to make the filter in a tXMLMap to have on one flow the "gold" values and on the other the "vip"values both followed by a tAggregateRow but then it doesn't seem possible to use a tUnite to group them.

Same with tReplicate ==> tFilterRow ==> tAggregateRow : impossible to use tUnite after ...

 

How I can proceed?

 

Anonymous
Not applicable

It is impossible to use tUnite after, this is not allowed to do in a cycle flow. As a workaround, you can store the counting result to global variable or context vairalbe on a tJavaRow, and then generate a new row for these two counting result on a tFixedFlowInput in next subjob.

eg:

....AggreGateRow--main--tJavaRow1

|onsubjobok

tFixeFlowInput--main--tLogRow

 

tJavaRow1:

context.sum_of_glod=input_row.gold

 

on tFixedFlowInput, define two columns:vip and glod, set their values with corresponding context variable.

 

Regards

Song

 

FPouget1651761130
Contributor
Contributor
Author

Thanks fot the tips

 

What I did:

tFileInputXml -> tXMLMap

  • -> tAggregateRow -> tfileOutputDelimited_1
  • -> tAggregateRow -> tfileOutputDelimited_2

 

|onsubjobok

tFileInputDelimited_1 --main--

  • tMap -> tfileOutputDelimited_3

tFileInputDelimited_2 --Lookup--

Anonymous
Not applicable

Thanks for your feedback! Personally, I'd like to store small temporary datasets in memory rather than writing to the filesystem.

 

FPouget1651761130
Contributor
Contributor
Author

my sample is small but my use case is huge 😉

Anonymous
Not applicable

This makes sense! In addition, remove the temporary file in the end of job if it isn't used any more; use context variable as file path if the job will be migrated to other environment, so that you can assign a new file path through job executable file if needed.