Is there a TextPad Plugin (64-bit) to convert TXT to XML?
Posted: Mon Jan 30, 2017 4:35 pm
Hello,
Is there a TextPad Plugin (64-bit) to convert TXT to XML?
Thanks!
Is there a TextPad Plugin (64-bit) to convert TXT to XML?
Thanks!
forums.textpad.com
https://forums.textpad.com/
Code: Select all
Source Document(1) - circa 1807
James Peters is the apparent creator of Source Document(1) which bears the following information in the lower left corner of the map:
A Plan of the French grant on Mount desert The shore to
old settlers lots copyed [sic] from a Plan taken John Peters, Esq.,
remainder of the Survey taken by me James Peters.
Bluehill, November, 1807Code: Select all
<?xml version="1.0" encoding="UTF-8"?><Content>
<p>Source Document(1) - circa 1807</p><p>James Peters is the apparent creator of Source Document(1) which bears the following information in the lower left corner of the map:</p><p></p><p>A Plan of the French grant on Mount desert The shore to</p><p>old settlers lots copyed [sic] from a Plan taken John Peters, Esq.,</p><p>remainder of the Survey taken by me James Peters.</p><p>Bluehill, November, 1807</p></Content>Code: Select all
import java.io.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.sax.*;
public class ToXML {
BufferedReader in;
StreamResult out;
TransformerHandler th;
public static void main(String args[]) {
new ToXML().begin();
}
public void begin() {
try {
in = new BufferedReader(new FileReader("data.txt"));
out = new StreamResult("data.xml");
openXml();
String str;
while ((str = in.readLine()) != null) {
process(str);
}
in.close();
closeXml();
} catch (Exception e) {
e.printStackTrace();
}
}
public void openXml() throws ParserConfigurationException, TransformerConfigurationException, SAXException {
SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
th = tf.newTransformerHandler();
// pretty XML output
Transformer serializer = th.getTransformer();
serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
th.setResult(out);
th.startDocument();
th.startElement(null, null, "inserts", null);
}
public void process(String s) throws SAXException {
th.startElement(null, null, "option", null);
th.characters(s.toCharArray(), 0, s.length());
th.endElement(null, null, "option");
}
public void closeXml() throws SAXException {
th.endElement(null, null, "inserts");
th.endDocument();
}
}Yes, that's correct.So your overall point is: put every line of a text file into an XML element?
Different picture files can hold different metadata, and none of that has to be XML. Now I even wonder why you want every text line in one separate XML element when the whole text (including linebreaks) can be in one single XML element as well - your screenshot is a good example for that - it would even make more sense to put into such a layout:Kelly wrote:add verbose custom metadata to georeferenced imagery
Code: Select all
...
<comment>Observations and notes regarding the plan.
Secrets not included.</comment>
<time>2017-01-28T09:30:00 -0500</time>
<author>Margie Coffin Brown</author>
<address>174 Liberty Street
Concor, MA 01742</address>
<phone>978 318 7830</phone>
...