The CreatorCon Call for Content is officially open! Get started here.

XML File Import - Data Source Issue in defining the XPath

avinashrvn
Tera Contributor

Hello Experts,

Could you please check this. I had difficulties defining the Xpath in the data source to import the xml file. I need 3 fields to be created in the source table (asset_tag, dv_model_category, lastLogonAD)

 

This is the Sample XML file-

<?xml version="1.0" encoding="UTF-8"?>
<results preview="0">
<meta>
<fieldOrder>
<field>asset_tag</field>
<field>dv_model_category</field>
<field>lastLogonAD</field>
</fieldOrder>
</meta>
<messages>
<msg type="DEBUG">Configuration initialization for /opt/splunk/etc took 96ms when dispatching a search (search ID: 159XXXXXX.23XXX_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)</msg>
<msg type="DEBUG">search context: user="servicenowapi", app="search", bs-pathname="/opt/splunk/etc"</msg>
<msg type="INFO">Successfully read lookup file '/opt/splunk/etc/apps/XXXX_IT_Operations/lookups/servicenow_asset.csv'.</msg>
</messages>

<result offset="0">
<field k="asset_tag">
<value><text>9AG7XYZ</text></value>
</field>
<field k="dv_model_category">
<value><text>Computers</text></value>
</field>
<field k="lastLogonAD">
<value><text>12-31-2019</text></value>
</field>
</result>
<result offset="1">
<field k="asset_tag">
<value><text>046418543153</text></value>
</field>
<field k="dv_model_category">
<value><text>Computers</text></value>
</field>
<field k="lastLogonAD">
<value><text>12-31-1969</text></value>
</field>
</result>

<result offset="2">
<field k="asset_tag">
<value><text>046450243153</text></value>
</field>
<field k="dv_model_category">
<value><text>Computers</text></value>
</field>
<field k="lastLogonAD">
<value><text>12-31-1969</text></value>
</field>
</result>

1 ACCEPTED SOLUTION

The xml you provided is missing </results> as a closing tag at the end. However, /results/result and //results are returning correct results.

 

You can try Xpath here. 

https://codebeautify.org/Xpath-Tester#

 

when you validate the correct Xpath by testing over the above link. you can use that in Data source and try deleting the staging table and run new data source so that it could pick right fields for staging table. 

 

Please mark this accepted & helpful if it answered your question.

 

Thanks & Regards,
Sharjeel

Regards,
Muhammad

View solution in original post

6 REPLIES 6

MrMuhammad
Giga Sage

Please Try below

/results/result
Regards,
Muhammad

Only one filed is created as "filed/value/text" and all asset_tag values are loaded in it when i use the path /results/result

 

find_real_file.png

Have you tried 

results//result

or

results[@preview="0"]//result

Regards,
Muhammad

It is still the same, Only asset_tag values are being loaded under the field "filed/value/text" and other 2 attributes are being ignored.

Could you save the above content as .xml and try this? Tried other options as well, it doesn't seem to be working, may be i was missing something.