10.3.38 getXmlElem (obtains contents of elements of XML data)
Syntax
getXmlElem [-e character-encoding] element-name [file-path-name]
Description
This command searches for an element name from the XML file specified for argument and outputs all fully matched elements. Output is performed after deleting line breaks contained in elements.
Arguments
- -e character-encoding
-
- Windows edition
-
This command specifies the character encoding for XML file. "SJS" or "UTF8" can be specified. If you do not specify this option, the character encoding is treated as UTF8.
- UNIX edition
-
This command specifies the character encoding for XML file with the syntax of value of the environment variable LANG. For values that can be specified, see 2.2.4 Encoding used in JP1/Advanced Shell.
If you do not specify this option, assume that the character encoding is specified in the format of the value of the LANG environment variable in the environment where JP1/Advanced Shell operates.
For example, if the XML file with the character encoding UTF-8 in AIX is treated, specify "JA_JP" or "JA_JP.UTF-8" for -e option.
- element-name
-
This command specifies the element name to be searched.
- file-path-name
-
This command specifies the path of a XML file. If you do not specify the file path name, input from the standard input.
Output to the standard output
Contents of elements of XML data.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
Not less than 1 |
Termination with an error |
Notes
-
If matching elements are not found, the command terminates with an error.
-
Contents of elements to be output include all described strings. Therefore, items including CDATA section are output.
-
Description of entity reference including "&" included in contents of an element is output as it is.
If metacharacter in regular Expression is included in the element name, specify the element name by escaping with \.
- Example:
-
You need to specify as follows when you search for the element name "name+":
getXmlElem 'name\+' test.xml
-
Contents of element cannot be output correctly if the element with the same name is nested.
- Example:
-
<value><value>100</value></value>
However, if the nested element contains other elements, contents of the innermost element can be output as follows:
- Example (tst.xml)
-
<value><name><value>100</value></name></value>
getXmlElem name test.xml | getXmlElem value
-
This part creates a temporary file by using the adshmktemp command. Therefore, the temporary file might remain when the command receives a forced termination request while the part is being executed. In this case, delete the temporary file manually. Temporary file is created in the directory defined with the TEMP_FILE_DIR parameter of the temporary file according to the following naming rule:
getXmlElem_job-ID_process-ID_time-information_file sequence number
Examples
XML data (data.xml) <data> <city> <name id="0001">Yokohama</name> <name id="0002">Kawasaki</name> </city> </data> getXmlElem -e SJIS name data.xml # The following contents are output: Yokohama Kawasaki XML data (data2.xml) <name> <city> <name id="0001">Yokohama</name> <name id="0002">Kawasaki</name> </city> </name> getXmlElem city data2.xml | getXmlElem name # The following contents are output: Yokohama Kawasaki