[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: FAQ candidate? parsing line-separated text files (was: R

Subject: Re: FAQ candidate? parsing line-separated text files (was: Re: Off-topic: DOS script for XML directory listing)
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Thu, 02 Mar 2000 15:40:08 +0000
parsing text file java
"Robert C. Lyons" wrote:

> I see one problem:
> The solution doesn't work if any of the file names
> in xmlDir.lst contains an ampersand
> (e.g., "Tom & Jerry.doc"), since an external parsed
> general entity (e.g., xmlDir.lst) can not contain
> an unescaped ampersand.
> 
Ouch! I hadn't thought of that.

> Perhaps there is a DOS command that is similar to
> the Unix sed command; your batch program could then
> replace each ampersand in the xmlDir.lst file with "&amp;".
> I'm not aware of such a DOS command.
> 
Nor am I. Unless there is a DOS edit.com guru out there...?

I was trying to do two things - (1) provide a utility, and (2) offer a
useful technique. I think the technique still stands, but with the
constraint that the input file can't contain ampersands.

I've written a little java program that can be called with jview (I hope
a reasonable assumption in most windows environments) and modified the
batch file. This should rescue the utility, if not its dignity.

Francis.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xmlDir [
<!ENTITY xmlDirList
           SYSTEM "xmlDir.lst">    
  ]>

<xmlDir>&xmlDirList;</xmlDir>
import java.io.*;

public class EscapeAmps
{
  static final int amp = '&';
  public static void main(String[] args)
  {
    int b;
    DataInputStream stdIn = new DataInputStream(System.in);
    try
    {
      while((-1)!=(b=stdIn.read()))
      {
        switch(b)
        {
          case amp:
          {
            System.out.print("&amp;");
            break;
          }
          default:
          {
            System.out.print((char)b);
            break;
          }
        }//switch (b)
      }//while(!eof())
    }
    catch(Exception e)
    {
      return;
    }
    return;
  }
}

Attachment: EscapeAmps.class
Description: application/java

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.