Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
does this help:
https://help.qlik.com/en-US/qlikview/May2024/Subsystems/Client/Content/QV_QlikView/Scripting/use-quo...
What happens if you use single quotes?
I try search many info.
but if use single quotes, i get the same :
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.
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;