Skip to content

Commit fabb77f

Browse files
committed
Change default namespace id to _ and DEFAULT
1 parent 0dce939 commit fabb77f

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

README.adoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ xmlsect - Quickly query an XML file using XPath 1.0.
88

99
This tool reads a whole XML file into memory, extracts its XML Namespaces using a regular expression and then loads all the _namespaces_ for you.
1010

11-
When there is a default namespace, it automatically loads it under the namespace ID *ns*.
12-
An example XPath would then look like `/ns:a/ns:b/ns:c`.
13-
11+
When there is a default namespace, it automatically loads it under the namespace ID *_* (or *DEFAULT*).
12+
An example XPath would then look like `/_:a/_:b/_:c`.
1413

1514
== SYNOPSIS
1615

xmlsect.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ func extractXMLNS(b []byte) map[string]string {
3333
nsid := string(m[1])
3434
ns := string(m[2])
3535
if nsid == "" {
36-
nsid = "ns"
37-
fmt.Fprintf(os.Stderr, "Found default namespace: %s\nUse 'ns' as the namespace ID for xpath: /ns:a/ns:b/ns:c\n\n", ns)
36+
nsid = "DEFAULT"
37+
xmlnsMap[nsid] = ns
38+
nsid = "_"
39+
xmlnsMap[nsid] = ns
40+
fmt.Fprintf(os.Stderr, "Found default namespace: %s\nUse '_' or 'DEFAULT' as the namespace ID for xpath: /_:a/_:b/_:c\n\n", ns)
3841
} else {
3942
fmt.Fprintf(os.Stderr, "Found '%s' namespace: %s\n\n", nsid, ns)
43+
xmlnsMap[nsid] = ns
4044
}
41-
// TODO: Check for duplicate nsid
42-
xmlnsMap[nsid] = ns
4345
}
4446
return xmlnsMap
4547
}

0 commit comments

Comments
 (0)