How can I ignore \t and \n chars when parsing my XML?
Hi. I have a problem when parsing an XML file...
This part works (well, it doesn't cause any exceptions):
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try
{
DocumentBuilder builder = factory.newDocumentBuilder();
Document MyDocument = builder.parse(new File(FolderName +"\\XMLDoc.xml") );
}
catch (SAXException sxe)
{
// Error generated during parsing
Exception x = sxe;
if (sxe.getException() !=null)
x = sxe.getException();
x.printStackTrace();
}
catch (ParserConfigurationException pce)
{
// Parser with specified options can't be built
pce.printStackTrace();
}
catch (IOException ioe)
{
// I/O error
ioe.printStackTrace();
}
Afterward, I try the following code to traverse through my document:try
{
Node TargetNode = MyDocument.getDocumentElement();
Node NextNode = TargetNode.getFirstChild();
}
catch (Exception ex)
{
returnfalse;
}
returntrue;
TargetNode does in fact get the DocumentElement, TARGET. The problem is that NextNode ends up grabbing "\n\t", not the NEXT element!
Below is what my XML file looks like (except for the underscores, which I inserted to show where my file has tabs):
<?xml version="1.0" encoding="UTF-8"?>
<TARGET>
_<NEXT>
__<DATA>Default</DATA>
_</NEXT>
</TARGET>
And yes, I am sure that the encoding really IS UTF-8...
So, does anyone know how I can get it to ignore those whitespace characters and just give me the element that I want?
Thanks a bunch.

