One Star

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>
4 REPLIES
One Star

Re: Extract an XML attribute from a document

Hi,
Do you try with tFileInputXML ?
Seventeen Stars

Re: Extract an XML attribute from a document

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

tExtractXMLField is often use to extract a part of xml document (loop element from complex xml for example).
One Star

Re: Extract an XML attribute from a document

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 ?
One Star

Re: Extract an XML attribute from a document

> 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.