Help reading Nodes from an XML File

Hello everyone, need your help.
This is part of the XML file,*********

<FLD_NAME>ESTOPONEXCEPTION</FLD_NAME><FLD_VALUE>0</FLD_VALUE><FLD_TYPE>BOOL</FLD_TYPE>

<FLD_NAME>ERRORMSG</FLD_NAME><FLD_VALUE></FLD_VALUE><FLD_TYPE>STR</FLD_TYPE>

I would like to analyze the file and get the values ​​of:STOPONEXCEPTION,ERRORMSG
Just as if not empty / different from 0

Hi!

What platform are you hoping to do this on (Windows?) and is there anything else in the file before and after this? XML works based on path so we need to know all of the preceding and following content as well.

<First>
 <Second>
   <FLD_NAME></FLD_NAME>
 </Second>
</First>

Bill

<?xml version="1.0"?>

<POSSRV_STATUS>

So the reason i’m asking is that:

<?xml version="1.0"?>
<FLD_NAME>ESTOPONEXCEPTION</FLD_NAME><FLD_VALUE>0</FLD_VALUE><FLD_TYPE>BOOL</FLD_TYPE>
<FLD_NAME>ERRORMSG</FLD_NAME><FLD_VALUE></FLD_VALUE><FLD_TYPE>STR</FLD_TYPE>

Is not a valid XML document as it has two top level nodes. Are the FLD_NAME sections inside of a FLD node or something?

Can you share something that represents that XML document so we can help you build a query that works for this?

tnx i working on it -

Hi!

The following should work for grabbing the first one

(select "FLD_VALUE" of it as text) of selects "/CARSRV_STATUS/TERMINAL/FIELD[FLD_NAME = 'ESTOPONEXCEPTION']" of xml document of file "C:\pathto\test.xml" 

Essentially we are using XML Pathing to find the node and then grabbing the value FLD_VALUE from it.

This gets us the XML Document:

xml document of file "C:\pathto\test.xml" 

This gets us the field node with a FLD_NAME value of ESTOPONEXCEPTION

selects "/CARSRV_STATUS/TERMINAL/FIELD[FLD_NAME = 'ESTOPONEXCEPTION']" of xml document ...

So now we have the node:

<FLD_NAME>ESTOPONEXCEPTION</FLD_NAME><FLD_VALUE>0</FLD_VALUE><FLD_TYPE>BOOL</FLD_TYPE>

And to get the FLD_VALUE we just do:

(select "FLD_VALUE" of it as text) of ...

Notice we do select "FLD_VALUE" of it to get to the value but that returns an XML node so we use as text to get the value as a string.

You should be able to modify the above relevance to get the other values you’re interested in.

Fantastic, but i get multi RESULT
Can you help me get the figure when a value other than 0

(select “FLD_VALUE” of it as text) of selects “/CARSRV_STATUS/TERMINAL/FIELD[FLD_NAME = ‘ESTOPONEXCEPTION’]” of xml document of file “C:\pathto\test.xml”

Just as if not empty / different from 0

If you are getting multiple results then that means you’ve got multiple fields with a FLD_NAME of ESTOPONEXCEPTION so we need to figure out which one you actually want.

Can you let me know the XML parts that have a FIELD with a FLD_NAME of ESTOPONEXCEPTION?

And if you were looking at the file yourself how would you determine which is the value you want if there are two different values in the XML?

Are you saying that there may be multiple values but we want to ignore the ones that are 0? Can you elaborate on your last statement?

1 Like

Are you saying that there may be multiple values but we want to ignore the ones that are 0?
YES

Normally the file will contain only the values 0 or blank

We’ve got two ways to do this – we can filter using xpath like we did with ESTOPONEXCEPTION or we can get our results and use relevance to filter it. I’ve given examples of both below:

Using XPATH

We can add another condition to our xpath like this:

(select "FLD_VALUE" of it as text) of selects "/CARSRV_STATUS/TERMINAL/FIELD[FLD_NAME = 'ESTOPONEXCEPTION' and FLD_VALUE!='0']" of xml document of file "C:\pathto\test.xml" 

Notice the addition of FLD_VALUE!='0'

Note: As an exercise for the reader – this can also be simplified to just:

(it as text) of selects "/CARSRV_STATUS/TERMINAL/FIELD[FLD_NAME = 'ESTOPONEXCEPTION']/FLD_VALUE[. != '0']" of xml document of file "C:\pathto\test.xml" 

Using Relevance

We can just add a whose (it) clause to our current relevance to filter using relevance:

it whose (it != "0") of (select "FLD_VALUE" of it as text) of selects "/CARSRV_STATUS/TERMINAL/FIELD[FLD_NAME = 'ESTOPONEXCEPTION']" of xml document of file "C:\pathto\test.xml"
2 Likes

WOW
it whose (it != “0”) of (select “FLD_VALUE” of it as text) of selects “/CARSRV_STATUS/TERMINAL/FIELD[FLD_NAME = ‘ESTOPONEXCEPTION’]” of xml document of file “C:\users\eastonb\desktop\test.xml”

Fantastic, you’re a genius, you helped me a lot

Fantastic, you’re a genius, you helped me a lot

1 Like

I know this post is a bit old, but figured I’d try here since I am having a similar issue…

XML File:

<?xml version="1.0" standalone="yes" ?>
<!-- Copyright (c) 1999, 2010, Oracle. All rights reserved. -->
<!-- Do not modify the contents of this file by hand. -->
<INVENTORY>
<VERSION_INFO>
   <SAVED_WITH>11.2.0.2.0</SAVED_WITH>
   <MINIMUM_VER>2.1.0.6.0</MINIMUM_VER>
</VERSION_INFO>
<HOME_LIST>
<HOME NAME="Test1" LOC="D:\Test_home" TYPE="O" IDX="1"/>
</HOME_LIST>
</INVENTORY>

We are trying to simply pull the Home NAME as a result from the query below, but it returns as blank:

(it as text) of xpaths "INVENTORY/VERSION_INFO/HOME_LIST/HOME/Name" of xml document of file "C:\Program Files (x86)\Oracle\Inventory\ContentsXML\inventory.xml"

We do have success pulling the version from this same XML document via the command below:

If exists file "C:\Program Files (x86)\Oracle\Inventory\ContentsXML\inventory.xml" then ((node values of child nodes of selects "INVENTORY/VERSION_INFO/SAVED_WITH" of xml document of file "C:\Program Files (x86)\Oracle\Inventory\ContentsXML\inventory.xml") as trimmed string) else "Not Applicable"

I am sure we are overlooking something silly so if someone could assist it would be greatly appreciated!

XML file seems truncated in your post.

XML SS

I attached it here

First comment field seems to be missing an ending tag? (line 2)

Is there a method around this? These are Oracle based inventory files so modifying them isn’t an option for us.

Actually it would help if the screenshot didn’t get cut off. There is an end tag there. XML SS