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?
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
You could have kindly answered "no", but if you need examples, I'm happy to provide them:
1 - Here's an example of an online conversion service taking text and adding the markup language needed for xml conformity
2 - Here's an example realized as per a StackOverflow request using Java; however, I'm not a programmer and was why I was hoping that there had already been a TextPad module written like this, perhaps using perl(?) instead
3 - Here's an example realized by Notepad++ using its own XML Tools Plugin
1 - Here's an example of an online conversion service taking text and adding the markup language needed for xml conformity
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, 1807
Code: 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();
}
}
- This one takes every line of a text file and puts it into an element. Even empty ones. And even multiple whitespaces, although XML will collapse them upon interpretation - instead they should be escaped thru entities.
- This one does quite the same, but uses other elements.
- Can't see any example there.
Yes, that's correct.So your overall point is: put every line of a text file into an XML element?
To explain a little further, I had been asking a software developer how one might add verbose custom metadata to georeferenced imagery. The initial response included more than one means with the xml option being ideal. So the txt file needed to be converted into xml before the metadata could be displayed in Global Mapper:
Regarding the Notepad++ example, the provided link to the XML Tools Plugin was just an example of the set of tools used by Notepad++ users; however, the tools only work with the 32-bit version of Notepad++ which I do not have. The plugin does not work with the 64-bit version of Notepad++ which I do have.
Browsing the offerings from TextPad's Add-Ons page, I didn't see any clear indications that a converter utility was available and thus the emergence of this thread.
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>
...