Re: an XML parser problem

Hello Frank,

This doesn't look like a specific Schema-related issue, rather something to be discussed in xml-dev or one of the Apache mailing
lists.

Regarding tutorials on parsing XML, you really have the embarassment of making a choice. Start to browse the W3C website itself (the
DOM Specification itself isn't quite a tutorial), look at Robin Cover's XML Pages (www.oasis-open.org) for lots of good pointers,
try www.xml.org etc. Work yourself through some sample code (such as ui.TreeView coming with the Xerces-J samples) and try to
understand what it does.

Frank Zhou wrote:

> Hi,All,
>
>    I am trying to use DOM parser to parse a simple XML
> file (in my local computer). I did  not get any error
> message in parsing the file, however, when I
> getDocument() from the parser and traverse it, I found
> that I got all the element and attribute names
> correctly as well as the document structure, but lost
> all the value information for the elements and
> attributes.

The content (“value”) of an DOM Element node is contained within its Text (and/or CDATASection) child node(s).

> Also, when I try to getElementsByTagName,
> I get 0 entries althougth I know there are elements in
> the file matches the tag name.
>
>     I guess I did not know how to use the DOM parser,
> can anyone out there kindly teach me on this?
>
> Thanks in advance.
> Steven
>
>     Here are the few lines I used in my code:
>
>             DOMParser parser = new DOMParser();
>             ErrorHandler errorHandler = new
> ErrorHandler();
>             parser.setErrorHandler(errorHandler);

Not sure what environment you are using: your attempt to instantiate the SAX ErrorHandler interface is probably ignored.


>             parser.parse(CONTROL_FILE_NAME);
>             Document document = parser.getDocument();
>
>             NodeList testEntries =
> document.getElementsByTagName("tagName");

Your getElementsByTagName() method call asks for elements named “tagName” -- of course, if tagName is a String variable containing a
tag name, you should use it unquoted.

Hoping this helps,

--
Jacques Deseyne
SWIFTAlliance WebStation Development Team
IT/Interfaces
S.W.I.F.T. SCRL
Tel: +32 2 655 45 87
http://becqw460.swift.com

This e-mail and any attachments thereto may contain information that is
confidential and/or proprietary and is intended for the sole use of
the recipient(s) named above. It is not intended to create or affect
any contractual arrangements between the parties. If you have received
this e-mail by mistake, please notify the sender and delete it immediately.
Thank you for your cooperation.

Received on Tuesday, 13 November 2001 05:11:48 UTC