.\" .\" *********************************************************************
.\" .\" *                                                                   *
.\" .\" *             Copyright 2020-2024, Intel Corporation                *
.\" .\" *                                                                   *
.\" .\" *                       All Rights Reserved.                        *
.\" .\" *                                                                   *
.\" .\" *********************************************************************

.TH ethxmlextract 8 "Intel Corporation" "Copyright(C) 2020\-2024" "EFSFFCLIRG (Man Page)"
.SH NAME
ethxmlextract


.PP
Extracts element values from XML input and outputs the data in CSV format. ethxmlextract is intended to be used with ethreport, to parse and filter its XML output, and to allow the filtered output to be imported into other tools such as spreadsheets and customer-written scripts. ethxmlextract can also be used with any well-formed XML stream to extract element values into a delimited format.
.PP
Five sample scripts are available as prototypes for customized scripts. They combine various calls to ethreport with a call to ethxmlextract with commonly used parameters.
.SH Syntax
ethxmlextract [-v][-H][-d  \fIdelimiter\fR][-e  \fIextract\(ulelement\fR]
.br

[-s  \fIsuppress\(ulelement\fR][-X  \fIinput\(ulfile\fR] [-P  \fIparam\(ulfile\fR]
.SH Options

.TP 10
--help

Produces full help text.

.TP 10
-v/--verbose

Produces verbose output. Includes output progress reports during extraction and output prepended wildcard characters on element names in output header record.

.TP 10
-H/--noheader

Does not output element name header record.

.TP 10
-d/--delimit \fIdelimiter\fR

Uses single character or string as the delimiter between element names and element values. Default is semicolon.

.TP 10
-e/--extract \fIextract\(ulelement\fR

Specifies the name of an XML element to extract. Elements can be nested in any order, but are output in the order specified. Elements can be specified multiple times, with a different attribute name or attribute value. An optional attribute (or attribute and value) can also be specified with elements:

.RS

.IP \(bu
-e \fIelement\fR
.IP \(bu
-e \fIelement:attrName\fR
.IP \(bu
-e \fIelement:attrName:attrValue\fR

.RE

.TP 10
.BR

.PP

.B NOTE:

.RS

.IP \(bu
Elements can be compound values separated by a dot. For example, Switches.Node is a Node element contained within a Switches element.
.IP \(bu
To output the attribute value as opposed to the element value, a specification such as -e NICs.Node:id can be used. This will output the value of the id attribute of any Node elements within NICs element.
.IP \(bu
If desired, a specific element can be selected by its attribute value, such as -e NICs.Node.PortInfo:LinkSpeedActive:100Gb, which will output the value of the PortInfo element within Node element where the PortInfo element has an attribute of LinkSpeedActive with a value of 100Gb.
.IP \(bu
A given element can be specified multiple times each with a different AttrName or attrValue.

.RE


.TP 10
-s/--suppress \fIsuppress\(ulelement\fR

Specifies the name of an XML element to suppress extraction. Can be used multiple times (in any order). Supports the same syntax as -e.

.TP 10
-X/--infile \fIinput\(ulfile\fR

Parses XML from \fIinput\(ulfile\fR.

.TP 10
-P/--pfile \fIparam\(ulfile\fR

Reads command parameters from param\(ulfile.

.SH Example

.PP
Here is an example of ethreport output filtered by ethxmlextract :
.PP

.br
# ethreport -o comps -x | ethxmlextract -d \\; -e NodeDesc -e ChassisID -e NumPorts -s Neighbor
.br

Getting All Fabric Records...
.br

Done Getting All Fabric Records
.br

NodeDesc;ChassisID;NumPorts
.br

hdarei001;0x0000444ca8e9ddd5;41
.br

hds1fnc7041-eno1;0x0000a4bf01553c89;1
.br

hds1fnc7041-eth1;0x0000a4bf01553c89;1
.br

hds1fnc7061-eth2;0x0000a4bf015540f0;1
.br

hds1fnc7061-eno1;0x0000a4bf015540f0;1
.br

hds1fnc7061-eth1;0x0000a4bf015540f0;1
.br

hds1fnc7081-eth2;0x0000a4bf01554175;1
.br

hds1fnc7081-eno1;0x0000a4bf01554175;1
.br

hds1fnc7081-eth1;0x0000a4bf01554175;1

.br

.SH Details

.PP
ethxmlextract is a flexible and powerful tool to process an XML stream. The tool:
.IP \(bu
Requires no specific element names to be present in the XML.
.IP \(bu
Assumes no hierarchical relationship between elements.
.IP \(bu
Allows extracted element values to be output in any order.
.IP \(bu
Allows an element\[aq]s value to be extracted only in the context of another specified element.
.IP \(bu
Allows extraction to be suppressed during the scope of specified elements.
.PP
ethxmlextract takes the XML input stream from either stdin or a specified input file. ethxmlextract does not use or require a connection to a fabric.
.PP
ethxmlextract works from two lists of elements supplied as command line or input parameters. The first is a list of elements whose values are to be extracted, called
\fIextraction elements\fR

. The second is a list of elements for which extraction is to be suppressed, called
\fIsuppression elements\fR

. When an extraction element is encountered and extraction is not suppressed, the value of the element is extracted for later output in an extraction record. An extraction record contains a value for all extraction elements, including those that have a null value.
.PP
When a suppression element is encountered, then no extraction is performed during the extent of that element, from start through end. Suppression is maintained for elements specified inside the suppression element, including elements that may happen to match extraction elements. Suppression can be used to prevent extraction in sections of XML that are present, but not of current interest. For example, NodeDesc or IfAddr inside a Neighbor specification of ethreport can be suppressed.
.PP
ethxmlextract attempts to generate extraction records with data values that are valid at the same time. Specifying extraction elements that are valid in the same scope produces a single record for each group of extraction elements. However, mixing extraction elements from different scopes (including different XML levels) may cause ethxmlextract to produce multiple records.
.PP
ethxmlextract outputs an extraction record under the following conditions:
.IP \(bu
One or more extraction elements containing a non-null value go out of scope (that is, the element containing the extraction elements is ended) and a record containing the element values has not already been output.
.IP \(bu
A new and different value is specified for an extraction element and an extraction record containing the previous value has not already been output.
.PP
Element names (extraction or suppression) can be made context-sensitive with an enclosing element name using the syntax element1.element2. In this case, element2 is extracted (or extraction is suppressed) only when element2 is enclosed by element1.
.PP
The syntax also allows \[aq] * \[aq] to be specified as a wildcard. In this case, *.element3 specifies element3 enclosed by any element or sequence of elements (for example, element1.element3 or element1.element2.element3). Similarly, element1.*.element3 specifies element3 enclosed by element1 with any number of (but at least 1) intermediate elements.
.PP
ethxmlextract prepends any entered element name not containing a \[aq] * \[aq] (anywhere) with \[aq] *. \[aq], matching the element regardless of the enclosing elements.
.PP

.B NOTE:
Any element names that include a wildcard should be quoted to the shell attempting to wildcard match against filenames.


.PP
At the beginning of operation, ethxmlextract, by default, outputs a delimited header record containing the names of the extraction elements. The order of the names is the same as specified on the command line and is the same order as that of the extraction record. Output of the header record can be disabled with the -H option. By default, element names are shown as they were entered on the command line. The -v option causes element names to be output as they are used during extraction, with any prepended wildcard characters.
.PP
Options (parameters) to ethxmlextract can be specified on the command line, with a parameter file, or using both methods. A parameter file is specified with -P \fIparam\(ulfile\fR. When a parameter file specification is encountered on the command line, option processing on the command line is suspended, the parameter file is read and processed entirely, and then command line processing is resumed.
.PP
Option syntax within a parameter file is the same as on the command line. Multiple parameter file specifications can be made, on the command line or within other parameter files. At each point that a parameter file is specified, current option processing is suspended while the parameter file is processed, then resumed. Options are processed in the order they are encountered on the command line or in parameter files. A parameter file can be up to 8192 bytes in size and may contain up to 512 parameters.
