Skip to content

Commit d35219a

Browse files
committed
XML: save path to XML data when applicable
This change also adds a getPath() method to retrieve said path.
1 parent 71e4ec7 commit d35219a

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

src/main/java/org/scijava/util/XML.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
*/
6868
public class XML {
6969

70+
/** Path to the XML document (e.g., a file or URL). */
71+
private final String path;
72+
7073
/** The parsed XML DOM. */
7174
private final Document doc;
7275

@@ -77,38 +80,49 @@ public class XML {
7780
public XML(final File file) throws ParserConfigurationException,
7881
SAXException, IOException
7982
{
80-
this(loadXML(file));
83+
this(file.getAbsolutePath(), loadXML(file));
8184
}
8285

8386
/** Parses XML from the given URL. */
8487
public XML(final URL url) throws ParserConfigurationException,
8588
SAXException, IOException
8689
{
87-
this(loadXML(url));
90+
this(url.getPath(), loadXML(url));
8891
}
8992

9093
/** Parses XML from the given input stream. */
9194
public XML(final InputStream in) throws ParserConfigurationException,
9295
SAXException, IOException
9396
{
94-
this(loadXML(in));
97+
this(null, loadXML(in));
9598
}
9699

97100
/** Parses XML from the given string. */
98101
public XML(final String s) throws ParserConfigurationException,
99102
SAXException, IOException
100103
{
101-
this(loadXML(s));
104+
this(null, loadXML(s));
102105
}
103106

104107
/** Creates an XML object for an existing document. */
105108
public XML(final Document doc) {
109+
this(null, doc);
110+
}
111+
112+
/** Creates an XML object for an existing document. */
113+
public XML(final String path, final Document doc) {
114+
this.path = path;
106115
this.doc = doc;
107116
xpath = XPathFactory.newInstance().newXPath();
108117
}
109118

110119
// -- XML methods --
111120

121+
/** Gets the path to the XML document, or null if none. */
122+
public String getPath() {
123+
return path;
124+
}
125+
112126
/** Gets the XML's DOM representation. */
113127
public Document getDocument() {
114128
return doc;

0 commit comments

Comments
 (0)