Are you expecting to get the text in the element <b>?
This code is not accurate, since if you supply the same XML document without
the corresponding DTD
e.g. <!ELEMENT a (b)>
then the first child, that you expect to be <b> element, will be a
whitespace, which in turn is a #PCDATA, and not an element.
Try to iterate over the whole DOM tree, also have a look at the sample code
examples that come with the xercesJ-2.
Lance Zhang wrote:
> OK,
>
> The code is like
>
> DocumentBuilderFactory
> factory=DocumentBuilderFactory.newInstance();
> DocumentBuilder builder=factory.newDocumentBuilder();
> Document doc=builder.parse(new File("c:/a.xml");
> String
> value=doc.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
> //value come back something like ||
>
> a.xml
> <?xml version="1.0" ?>
> <a>
> <b>This is a test</b>
> </a>
>
> thanks/lance
>
> --- Xuemin Guan <[EMAIL PROTECTED]> wrote:
> > When posting such a question, it will be very
> > helpful if the code snippet
> > and xml sample
> > file can be included.
> >
> > ----- Original Message -----
> > �??信�??: "Lance Zhang" <[EMAIL PROTECTED]>
> > �?�?^ : <[EMAIL PROTECTED]>
> > �??信�-��?, : 2002�?�??8�-?18:09
> > 件�?? : Problem in Dom parser
> >
> >
> > > Hi,
> > >
> > > I got a problem when using DOM parser in
> > > javax.xml.parsers package.
> > >
> > > I can not use getNodeValue() to get a text node
> > value.
> > > It return me some strange characters in doing that
> > > although it is a very simple xml file.
> > >
> > > Also, the node.getElementsByTagName always return
> > me
> > > an empty nodelist although it was obvious not
> > null.
> > >
> > > Does anyone have same kind of experience? does
> > this
> > > related to the encoding?
> > >
> > > thanks/Lance
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Yahoo! Movies - coverage of the 74th Academy
> > Awards®
> > > http://movies.yahoo.com/
> > >
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > >
> > >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> >
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Movies - coverage of the 74th Academy Awards�
> http://movies.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]