473,467 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Whitespace problem - Xerces & Java - Anyone?


I have been trying with no result, to force Xerces parsers to ignore
whitespace in my XML file. I have tried several of the NG suggested
setFeature() methods in DOMParser to no avail.

I have now started to use the newest version of Xerces and as a result
I stopped using DOMParser. The following fragment of my code shows how
I create the parser and parse my XML file, which still has <null>
#text fields for whitespace. How can I force Xerces to ignore them?

Thanks,
John

Java Code:
=======

public class XMLConvert {

private DocumentBuilderFactory builderFactory;
private DocumentBuilder docFactory;
private Document inDoc;

public static void main(String[] args)
{
XMLConvert xml = null;

try {
xml = new XMLConvert(new FileInputStream(new File(args[0])));
} catch(Exception e) {
e.printStackTrace();
}

}

public XMLConvert(InputStream is)
{
try {
builderFactory = DocumentBuilderFactory.newInstance();

docFactory = builderFactory.newDocumentBuilder();

inDoc = docFactory.parse(is);
} catch(Exception e) {
e.printStackTrace();
}
}

My simple XML file:
============
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
<Body>
Test
</Body>
</Envelope>

Output from Java (children of root element):
============================

Node Name: #text
Local Name: null
URI: null

Node Name: Body
Local Name: null
URI: null

Node Name: #text
Local Name: null
URI: null
Jul 20 '05 #1
1 6004
Hi,

this method allow white spaces to be ignored :
builderFactory.setIgnoringElementContentWhitespace (true);
but you must specify a grammar (a DTD) for your document (the parser
can't guess which spaces can be ignored)

see JAXP documentation :
http://java.sun.com/j2se/1.4.2/docs/...erFactory.html

John wrote:
I have been trying with no result, to force Xerces parsers to ignore
whitespace in my XML file. I have tried several of the NG suggested
setFeature() methods in DOMParser to no avail.

I have now started to use the newest version of Xerces and as a result
I stopped using DOMParser. The following fragment of my code shows how
I create the parser and parse my XML file, which still has <null>
#text fields for whitespace. How can I force Xerces to ignore them?

Thanks,
John

Java Code:
=======

public class XMLConvert {

private DocumentBuilderFactory builderFactory;
private DocumentBuilder docFactory;
private Document inDoc;

public static void main(String[] args)
{
XMLConvert xml = null;

try {
xml = new XMLConvert(new FileInputStream(new File(args[0])));
} catch(Exception e) {
e.printStackTrace();
}

}

public XMLConvert(InputStream is)
{
try {
builderFactory = DocumentBuilderFactory.newInstance();

docFactory = builderFactory.newDocumentBuilder();

inDoc = docFactory.parse(is);
} catch(Exception e) {
e.printStackTrace();
}
}


--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bugbear | last post by:
Subject pretty much says it all. I'd like to parse XML (duh!) using Xerces (because its fast, and reliable, and comprehensive, and supports lots of features). I'd like to conform to standards...
0
by: Pud | last post by:
Hiya, I was wondering if anyone could help me, I am trying to create an example program that uses the xerces XML parser in Java. Unfortunately I have come across a problem when using this...
0
by: Curtiss Howard | last post by:
I'm using Xerces 2.4.0 and I've got a schema (converted from a DTD) for my XML documents. However, Xerces will NOT ignore the whitespace between elements. These are the options I've set for the...
0
by: Dale Gerdemann | last post by:
I've been trying to use DOM level 3 with xerces-2_6_2. There's a sample called samples/DOM3.java, but I've had trouble with compilation. I've downloaded Xerces-J-bin.2.6.2 and...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
7
by: Georg J. Stach | last post by:
Hi, as mentioned above I'd like to validate a simple XML-document with a simple DTD. For this, I use Java and Xerces. But, when I have tags of this form: <tag>some characters in here</tag> ...
2
by: Carlitos | last post by:
Hi there, A class in Xerces J-API (Java) called TextImpl contains a property that returns whether the text is ignorable whitespace...
2
by: Carlitos | last post by:
Hi there, A class in Xerces J-API (Java) called TextImpl contains a property that returns whether the text is ignorable whitespace...
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.