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
|
"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 "&".
> 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("&");
break;
}
default:
{
System.out.print((char)b);
break;
}
}//switch (b)
}//while(!eof())
}
catch(Exception e)
{
return;
}
return;
}
}Attachment:
EscapeAmps.class
Description: application/java
|