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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Snaigius213
Contributor
Contributor

Generating XML from QVD, double quotes

Hello,

trying generate XML file from QVD file, but have problems with quotes.

IF in code i write - '<?xml version="1.0" encoding="UTF-8"?>'

at result file i get "<?xml version=""1.0"" encoding=""UTF-8""?>"

and in data rows, where are values i need values insert in quotes ("xxx"), but finally get ""xxx""

Here is my script:

 

SET vSourceFile = 'xxx.qvd';
SET vOutputFile = 'xxx.xml';

TempXML:
LOAD
    '<?xml version="1.0" encoding="UTF-8"?>' AS XML_LINE
AUTOGENERATE 1;

CONCATENATE (TempXML)
LOAD
    '<ROOT><InitStocks>' AS XML_LINE
AUTOGENERATE 1;

STOCK_DATA:
LOAD 
    CUST_ID,
    STATUS,
    DTLM,
    STOCK,
    LOT_ID,
    LOCALCODE,
    WAREH_CODE
FROM $(vSourceFile) (qvd);

FOR i = 0 TO NoOfRows('STOCK_DATA') - 1
    LET vXMLRow = '<InitStock CUST_ID=' & Trim(Peek('CUST_ID', i, 'STOCK_DATA')) & ' ' &
                  'STATUS=' & Trim(Peek('STATUS', i, 'STOCK_DATA')) & ' ' &
                  'DTLM=' & Trim(Peek('DTLM', i, 'STOCK_DATA')) & ' ' &
                  'STOCK=' & Trim(Peek('STOCK', i, 'STOCK_DATA')) & ' ' &
                  'LOT_ID=' & Trim(Peek('LOT_ID', i, 'STOCK_DATA')) & ' ' &
                  'LOCALCODE=' & Trim(Peek('LOCALCODE', i, 'STOCK_DATA')) & ' ' &
                  'WAREH_CODE=' & Trim(Peek('WAREH_CODE', i, 'STOCK_DATA')) & ' />';
    CONCATENATE (TempXML)
    LOAD '$(vXMLRow)' AS XML_LINE AUTOGENERATE 1;
NEXT;

CONCATENATE (TempXML)
LOAD '</InitStocks></ROOT>' AS XML_LINE
AUTOGENERATE 1;

STORE TempXML INTO [$(vOutputFile)] (txt);

 

 

Tryed use Chr(34), But nothing helps.

If here i write " -  'STATUS="' & Trim(Peek('STATUS', i, 'STOCK_DATA')) & '" ' &

in xml  i get:


"<InitStock CUST_ID=6 STATUS=""2"" DTLM=20241223 04:41 STOCK=168.0000 LOT_ID=0 LOCALCODE=4860019001421 WAREH_CODE=EN1 />"

-----------------------------------------------------------------
Now are writed macro, but i want remove the macro and make all in one script 


Snaigius213_0-1735824931955.png

 





Labels (2)
4 Replies
David_Friend
Support
Support

Snaigius213
Contributor
Contributor
Author

I try search many info.

but if use single quotes, i get the same :

Snaigius213_0-1735826055350.png

 



 

marcus_sommer

AFAIK it's not possible. Not because the Qlik-load wouldn't be able to create the wanted data-structure else the provided store-feature into a txt has no configurations in regard to the quote-handling. As far as there are any quotes they will be embedded with further ones.

Depending on the target you may replace the quotes with other chars and advising the target which chars are now which kind of quotes and/or using the feature that some targets interpret n following quotes as one quote - both are more theoretically possibilities as practically solutions ...

Another look may go to store the data into a *.qvx - which creates a xml but I never tried that in such a way and it may come with any other overhead ...

Therefore you may remain by the macro or involving any extra tool/batch in between the source and the target which adjusted/replaced the wrong quotes.

p_verkooijen
Partner - Specialist II
Partner - Specialist II

Hi, 

Tried all I could think of, and indeed not possible within Qlik, so I used powershell commands to replace these chars.

Replaced all wanted " with ### in the Qlik script, and used Powershell to replace them for the correct one.

For example

TempXML:
LOAD
'<?xml version=###1.0### encoding=###UTF-8###?>' AS XML_LINE
AUTOGENERATE 1;



Content of _ConvertSteps.ps1

(Get-Content Qlikraw.xml) -replace '"', '' | Out-File -encoding ASCII XMLStep1.xml
(Get-Content XMLStep1.xml) -replace '###', '"' | Out-File -encoding ASCII Import.xml
Del Qlikraw.xml
Del XMLStep1.xml

 

EXECUTE POWERSHELL.EXE /C C:\QlikView\XMLOutput\_ConvertSteps.ps1;