> Hello,
> I'm trying to build a simple Tokenzier For XML:
[quoted text clipped - 19 lines]
>
> any help ?
Is the keyword "Tokenizer" important? From your description of the
problem, it doesn't sounds like you want a tokenizer at all.
Did you try using Java's DOM or SAX API and just accepting whatever
default XML parser it uses?
- Oliver
Tony - 02 Aug 2006 08:04 GMT
Hey,
Sorry, I ment for Parser and not Tokenizer.
my mistake.
Flávio Barata - 02 Aug 2006 12:40 GMT
Try this Java 1.5 code:
public static void main(String[] args) throws Exception {
DocumentBuilderFactory factory1 =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder1 = factory1.newDocumentBuilder();
Document doc1 = builder1.parse(new File("yourFileToBeParsed.xml"));
System.out.println("> " +
getText(doc1.getElementsByTagName("Key").item(0)));
}
private static String getText(Node node) {
StringBuilder sb = new StringBuilder();
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node n = nodeList.item(i);
if (n.getNodeType() == Node.TEXT_NODE) {
sb.append(n.getNodeValue().trim());
}
}
return sb.toString();
}
-
Flavio Santos
> Hey,
> Sorry, I ment for Parser and not Tokenizer.
> my mistake.