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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Extract an XML attribute from a document

Hi all,
I have the following setup and I would like to extract the username from this XML.  I am currently using tExtractXMLField and I've tried this xpath query /sample/@UserName but I get an error of:
Error on line 1 of document  : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
It feels like I am missing something.  Any assistance would be greatly appreciated.
Thanks!!
<?xml version="1.0" encoding="UTF-8"?>
<sample APIVersion="2013.001" SourceServer="abc123" UserName="jsmith" Operation="Search">
<Search Guid="red" />
</sample>
Labels (3)
4 Replies
Anonymous
Not applicable
Author

Hi,
Do you try with tFileInputXML ?
Anonymous
Not applicable
Author

hi,
as Marie_Fr said, it should be easier to use tfileInputXml.
how do you propagate your xml content in tExtractedXmlField ?
What's the value of XML field ?
regards
laurent
0683p000009MAuR.png
tExtractXMLField is often use to extract a part of xml document (loop element from complex xml for example).
Anonymous
Not applicable
Author

This works for me in 5.6.1:
tFixedFlowInput > tConvertType > tExtractXMLField > tLogRow
tFixedFlowInput has line separator "$", field separator "£"
tConvertType convert string to Document with "automatic conversion" checkbox activated
tExtractXMLField loop on "/", with one output field "data" with xpath "/sample/@UserName"
I think that your input XML is invalid, check this with a tLogRow. Maybe a space or a BOM ?
Anonymous
Not applicable
Author

> Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
I had the same problem with a tFixedFlowInput and the XML prefixed/suffixed by ".
Then, if you see a Sax error, check if you have the character " around the XML, and remove it.