Skip to content

Commit b661b9e

Browse files
authored
Merge pull request #22 from mluis7/issue_21
issue_21 Multiple issues with default namespaces
2 parents 1849bcc + e7a0f12 commit b661b9e

File tree

9 files changed

+175
-99
lines changed

9 files changed

+175
-99
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ To log a trace of test commands to a file run
293293

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

296+
To test several instances running in background or simultaneously (issue #15)
297+
298+
BG=1 ./test-all.sh
299+
296300
## Generate an XML from an XSD and show its XPaths
297301
If an XSD file is provided and **xmlbeans** package is installed, try to create an XML instance and print the XPath from it.
298302

@@ -449,14 +453,15 @@ This simple command will extract the first `entry` element to `wiki-1.xml` file.
449453
```text
450454
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.
451455
452-
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>]
456+
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>]
453457
xml2xpath.sh [-h -v] [XSD OPTIONS] [COMMON XML/HTML OPTIONS] [XML OPTIONS] [HMTL OPTIONS]
454458
455459
456460
Options:
457461
458462
Basic:
459463
-h print this help message.
464+
-q do not print information messages, just xpath list.
460465
-v print version
461466
462467
XML/HTML Common Options:
@@ -473,7 +478,7 @@ HTML options:
473478
XML options:
474479
-n Set namespaces found on root element. Default namespace prefix is 'defaultns' but may be overriden with -o option.
475480
-o Override the default namespace definition by passing <prefix>=URI, e.g.: -o 'defns=urn:hl7-org:v3'
476-
-p Namespace prefix to use. No need to pass -n if used. EXPERIMENTAL.
481+
-p Namespace prefix to use. No need to pass -n if used and takes precedence if it is.
477482
-x xml file, will take precedence over -d option.
478483
479484
XSD options:
@@ -495,8 +500,13 @@ Examples:
495500
496501
xml2xpath.sh -a -n -l test.html Html file with absolute paths option
497502
498-
Reporting bugs:
499-
https://github.com/mluis7/xml2xpath/issues
503+
Environment:
504+
XML_XPATH_RTOUT Set XML file the read timeout. Default 5s.
505+
506+
XMLBEANS_HOME Set Apache XmlBeans home for xml instance creation from xsd file. Default: /usr/share/java/xmlbeans
507+
508+
Bugs:
509+
Report found bugs or feature requests at https://github.com/mluis7/xml2xpath/issues
500510
```
501511

502512
## Generate man page
@@ -507,4 +517,4 @@ To test the generated man page use:
507517
`MANPATH="./man" man man/xml2xpath.sh.1`
508518

509519
## Known issues
510-
* 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).
520+
* No one! ... that I know of :-p but [performance](#performance) with big documents can always be an issue.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.12.1
1+
0.12.2

man/xml2xpath.sh.1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.5.
2-
.TH XML2XPATH.SH "1" "November 2024" "xml2xpath.sh 0.12.1" "User Commands"
2+
.TH XML2XPATH.SH "1" "July 2025" "xml2xpath.sh 0.12.2" "User Commands"
33
.SH NAME
4-
xml2xpath.sh \- manual page for xml2xpath.sh 0.12.1
4+
xml2xpath.sh \- manual page for xml2xpath.sh 0.12.2
55
.SH SYNOPSIS
66
.B xml2xpath.sh
7-
[\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]
7+
[\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]
88
.SH DESCRIPTION
99
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.
1010
.IP
@@ -15,6 +15,9 @@ xml2xpath.sh [\-h \fB\-v]\fR [XSD OPTIONS] [COMMON XML/HTML OPTIONS] [XML OPTION
1515
\fB\-h\fR
1616
print this help message.
1717
.TP
18+
\fB\-q\fR
19+
do not print information messages, just xpath list.
20+
.TP
1821
\fB\-v\fR
1922
print version
2023
.SS "XML/HTML Common Options:"
@@ -48,7 +51,7 @@ Set namespaces found on root element. Default namespace prefix is 'defaultns' bu
4851
Override the default namespace definition by passing <prefix>=URI, e.g.: \fB\-o\fR 'defns=urn:hl7\-org:v3'
4952
.TP
5053
\fB\-p\fR
51-
Namespace prefix to use. No need to pass \fB\-n\fR if used. EXPERIMENTAL.
54+
Namespace prefix to use. No need to pass \fB\-n\fR if used.
5255
.TP
5356
\fB\-x\fR
5457
xml file, will take precedence over \fB\-d\fR option.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<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">
2+
<anon-wrap xmlns="http://example.com/anon-dflt">
3+
<t1>
4+
<b01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>1</b01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>
5+
</t1>
6+
<t2>
7+
<b01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>2</b01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>
8+
</t2>
9+
</anon-wrap>
10+
<?pitest?>
11+
<t3>
12+
<c0>3</c0>
13+
</t3>
14+
15+
<ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>ERROR: 0 elements found</ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>
16+
<ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>duplicate error</ns:a01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678z01234567890123456789012345678x>
17+
</root>

tests/resources/nodefaultns.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
<c:name>with namespace</c:name>
77
<c:type>qualified</c:type>
88
</m:ele>
9-
9+
<t:t1 xmlns:t="path_example3">
10+
<t:t2>t2 ns</t:t2>
11+
</t:t1>
1012
<noprefix>
1113
<type>unqualified</type>
1214
</noprefix>
13-
</root>
15+
</root>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<d:doc xmlns:d="urn:d" xmlns:e="urn:e">
2+
<a/><b/>
3+
<a/><c/>
4+
<a/>
5+
<a>
6+
<e:e/>
7+
<e:e/><b/>
8+
<e:e/>
9+
<e:e/>
10+
<e:e xmlns="urn:g">
11+
<x/>
12+
<x/>
13+
<x e:attr="val"/>
14+
</e:e>
15+
<e:e/>
16+
</a>
17+
<a/>
18+
</d:doc>

tests/resources/soap.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://example.com/ns1">
1+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://example.com/ns0">
22
<soap:Body>
3-
<incident xmlns="http://example.com/ns2">
3+
<a/>
4+
<incident xmlns="http://example.com/ns1"> <!-- -->
45
<Company type="String">Test</Company>
56
</incident>
6-
<incident1 xmlns="http://example.com/ns1">
7+
<incident1 xmlns="http://example.com/ns2">
78
<Company1 type="String">Test</Company1>
89
</incident1>
10+
<a/>
911
</soap:Body>
1012
</soap:Envelope>
1113

tests/test-xml-ns-02.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ test_run "TC01"
2525
test_result "$?"
2626

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

0 commit comments

Comments
 (0)