Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ To log a trace of test commands to a file run

dbg=1; trace="$HOME/tmp/all-tests.log" ./test-all.sh

To test several instances running in background or simultaneously (issue #15)

BG=1 ./test-all.sh

## Generate an XML from an XSD and show its XPaths
If an XSD file is provided and **xmlbeans** package is installed, try to create an XML instance and print the XPath from it.

Expand Down Expand Up @@ -447,14 +451,15 @@ This simple command will extract the first `entry` element to `wiki-1.xml` file.
```text
Print XPath present on xml or (if possible) xsd files. Based on xmllint utility, try to build all possible XPaths from an XML instance. The latter could be constructed from a provided XSD file.

Usage: xml2xpath.sh [-h -v] [-d file -f <tag name>] [-a -g -t -s <xpath>] [-n -p <ns prefix> -o <prefix>=URI -x <file>] [-l <file>]
Usage: xml2xpath.sh [-h -v -q] [-d file -f <tag name>] [-a -g -t -s <xpath>] [-n -p <ns prefix> -o <prefix>=URI -x <file>] [-l <file>]
xml2xpath.sh [-h -v] [XSD OPTIONS] [COMMON XML/HTML OPTIONS] [XML OPTIONS] [HMTL OPTIONS]


Options:

Basic:
-h print this help message.
-q do not print information messages, just xpath list.
-v print version

XML/HTML Common Options:
Expand All @@ -471,7 +476,7 @@ HTML options:
XML options:
-n Set namespaces found on root element. Default namespace prefix is 'defaultns' but may be overriden with -o option.
-o Override the default namespace definition by passing <prefix>=URI, e.g.: -o 'defns=urn:hl7-org:v3'
-p Namespace prefix to use. No need to pass -n if used. EXPERIMENTAL.
-p Namespace prefix to use. No need to pass -n if used and takes precedence if it is.
-x xml file, will take precedence over -d option.

XSD options:
Expand All @@ -493,8 +498,13 @@ Examples:

xml2xpath.sh -a -n -l test.html Html file with absolute paths option

Reporting bugs:
https://github.com/mluis7/xml2xpath/issues
Environment:
XML_XPATH_RTOUT Set XML file the read timeout. Default 5s.

XMLBEANS_HOME Set Apache XmlBeans home for xml instance creation from xsd file. Default: /usr/share/java/xmlbeans

Bugs:
Report found bugs or feature requests at https://github.com/mluis7/xml2xpath/issues
```

## Generate man page
Expand All @@ -505,4 +515,4 @@ To test the generated man page use:
`MANPATH="./man" man man/xml2xpath.sh.1`

## Known issues
* Multiple default namespaces in document: `-o` and/or `-s` may give [incorrect results](https://stackoverflow.com/questions/69380381/send-command-output-back-to-previous-subshell-in-pipe-for-processing).
* No one! ... that I know of :-p but [performance](#performance) with big documents can always be an issue.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.1
0.12.2
11 changes: 7 additions & 4 deletions man/xml2xpath.sh.1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.5.
.TH XML2XPATH.SH "1" "November 2024" "xml2xpath.sh 0.12.1" "User Commands"
.TH XML2XPATH.SH "1" "July 2025" "xml2xpath.sh 0.12.2" "User Commands"
.SH NAME
xml2xpath.sh \- manual page for xml2xpath.sh 0.12.1
xml2xpath.sh \- manual page for xml2xpath.sh 0.12.2
.SH SYNOPSIS
.B xml2xpath.sh
[\fI\,-h -v\/\fR] [\fI\,-d file -f <tag name>\/\fR] [\fI\,-a -g -t -s <xpath>\/\fR] [\fI\,-n -p <ns prefix> -o <prefix>=URI -x <file>\/\fR] [\fI\,-l <file>\/\fR]
[\fI\,-h -v -q\/\fR] [\fI\,-d file -f <tag name>\/\fR] [\fI\,-a -g -t -s <xpath>\/\fR] [\fI\,-n -p <ns prefix> -o <prefix>=URI -x <file>\/\fR] [\fI\,-l <file>\/\fR]
.SH DESCRIPTION
Print XPath present on xml or (if possible) xsd files. Based on xmllint utility, try to build all possible XPaths from an XML instance. The latter could be constructed from a provided XSD file.
.IP
Expand All @@ -15,6 +15,9 @@ xml2xpath.sh [\-h \fB\-v]\fR [XSD OPTIONS] [COMMON XML/HTML OPTIONS] [XML OPTION
\fB\-h\fR
print this help message.
.TP
\fB\-q\fR
do not print information messages, just xpath list.
.TP
\fB\-v\fR
print version
.SS "XML/HTML Common Options:"
Expand Down Expand Up @@ -48,7 +51,7 @@ Set namespaces found on root element. Default namespace prefix is 'defaultns' bu
Override the default namespace definition by passing <prefix>=URI, e.g.: \fB\-o\fR 'defns=urn:hl7\-org:v3'
.TP
\fB\-p\fR
Namespace prefix to use. No need to pass \fB\-n\fR if used. EXPERIMENTAL.
Namespace prefix to use. No need to pass \fB\-n\fR if used.
.TP
\fB\-x\fR
xml file, will take precedence over \fB\-d\fR option.
Expand Down
17 changes: 17 additions & 0 deletions tests/resources/long-element-names-local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<root xmlns:ns="http://example.com/ns" xmlns:ns0="http://example.com/ns0" xmlns:ns98="http://example.com/ns98" xmlns:ns17="http://example.com/ns17">
<anon-wrap xmlns="http://example.com/anon-dflt">
<t1>
<b01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>1</b01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>
</t1>
<t2>
<b01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>2</b01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>
</t2>
</anon-wrap>
<?pitest?>
<t3>
<c0>3</c0>
</t3>

<ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>ERROR: 0 elements found</ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>
<ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>duplicate error</ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>
</root>
6 changes: 4 additions & 2 deletions tests/resources/nodefaultns.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
<c:name>with namespace</c:name>
<c:type>qualified</c:type>
</m:ele>

<t:t1 xmlns:t="path_example3">
<t:t2>t2 ns</t:t2>
</t:t1>
<noprefix>
<type>unqualified</type>
</noprefix>
</root>
</root>
18 changes: 18 additions & 0 deletions tests/resources/ns-with-default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<d:doc xmlns:d="urn:d" xmlns:e="urn:e">
<a/><b/>
<a/><c/>
<a/>
<a>
<e:e/>
<e:e/><b/>
<e:e/>
<e:e/>
<e:e xmlns="urn:g">
<x/>
<x/>
<x e:attr="val"/>
</e:e>
<e:e/>
</a>
<a/>
</d:doc>
8 changes: 5 additions & 3 deletions tests/resources/soap.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://example.com/ns1">
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://example.com/ns0">
<soap:Body>
<incident xmlns="http://example.com/ns2">
<a/>
<incident xmlns="http://example.com/ns1"> <!-- -->
<Company type="String">Test</Company>
</incident>
<incident1 xmlns="http://example.com/ns1">
<incident1 xmlns="http://example.com/ns2">
<Company1 type="String">Test</Company1>
</incident1>
<a/>
</soap:Body>
</soap:Envelope>

4 changes: 2 additions & 2 deletions tests/test-xml-ns-02.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ test_run "TC01"
test_result "$?"

# PASSED: Replace defaultns prefix, relative path
test_opts=(-o 'defns=http://example.com/ns2' -s "//defns:incident")
test_opts=(-o 'defns=http://example.com/ns1' -s "//defns:incident")
test_run "TC02"
test_result "$?"
test_result "$?"
Loading