Is there a TextPad Plugin (64-bit) to convert TXT to XML?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Kelly
Posts: 34
Joined: Sat May 28, 2011 8:59 am
Location: Ellsworth, ME

Is there a TextPad Plugin (64-bit) to convert TXT to XML?

Post by Kelly »

Hello,

Is there a TextPad Plugin (64-bit) to convert TXT to XML?

Thanks!
User avatar
AmigoJack
Posts: 533
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

And what should "convert TXT to XML" consist of? It means more than the world may know - you could have asked for "converting pictures to games" which also raises many questions.
Kelly
Posts: 34
Joined: Sat May 28, 2011 8:59 am
Location: Ellsworth, ME

Post by Kelly »

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

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>
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

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();
    }
}
3 - Here's an example realized by Notepad++ using its own XML Tools Plugin
User avatar
AmigoJack
Posts: 533
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

  1. 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.
  2. This one does quite the same, but uses other elements.
  3. Can't see any example there.
So your overall point is: put every line of a text file into an XML element? May I add that XML alone is only of little use without an appropriate XSD? While the XML alone can be syntactically valid the XSD is used to check for semantic validity and also tells the end user which elements he has to expect. I can't see any sense in having an XML file only as self purpose - normally you want such a file for being processed automatically (and such a processor needs to know which elements to expect, hence the XSD).
Kelly
Posts: 34
Joined: Sat May 28, 2011 8:59 am
Location: Ellsworth, ME

Post by Kelly »

So your overall point is: put every line of a text file into an XML element?
Yes, that's correct.

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:

Image

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.
User avatar
AmigoJack
Posts: 533
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

Kelly wrote:add verbose custom metadata to georeferenced imagery
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:

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>
...
EXIF, XMP can easily hold custom metadata. IPTC virtually as well. And most file formats on their own (i.e. JPEG, PNG, TIFF...) can do it as well. So far I see you only wanting to add one piece of comment into a picture file, not thinking about how it could be found at a later time or used as a filter (find all pictures having an address in "Concor" in January).
Post Reply