Re: DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
- From: Michael Rauscher <michlmann@xxxxxx>
- Date: Sun, 13 Aug 2006 05:48:09 +0200
BeGreen schrieb:
Hi All,
javax.xml.parsers.DocumentBuilder's parse method is not able to parse
the xml file, when
the record has an empty tag without a value, such as <weight/>.
Any Java class, you may know which can parse that tag successfully or
even ignore it?
Thanks!
import java.io.*;
import javax.xml.parsers.*;
public class XMLTest {
public static final void main( String args[] ) throws Exception {
String xml =
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
"<root>\n" +
" <Record>\n" +
" <PartNo>01</PartNo>\n" +
" <weight/>\n" +
" </Record>\n" +
" <Record>\n" +
" <PartNo>2</PartNo>\n" +
" <weight>A</weight>\n" +
" </Record>\n" +
"</root>";
System.out.println( xml );
byte data[] = xml.getBytes("ISO-8859-1");
ByteArrayInputStream is = new ByteArrayInputStream( data );
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
builder.parse(is);
is.close();
System.out.println("Done.");
}
}
Bye
Michael
.
- Follow-Ups:
- Re: DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
- From: Andrew Thompson
- Re: DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
- References:
- Prev by Date: Re: DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
- Next by Date: Re: How to program with proxy
- Previous by thread: Re: DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
- Next by thread: Re: DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
- Index(es):
Relevant Pages
|