Extract an XML attribute from a document

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>
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).
Four Stars

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 ?
Four Stars

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.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch