[jdom-interest] Problem with mixed content

Vyacheslav Pedak san at most5.krasnoyarsk.su
Tue Sep 12 23:02:47 PDT 2000

Brett McLaughlin <brett.mclaughlin at lutris.com> wrote:

> > I have simple xml like this:
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <test>
> >   <element>
> >     text
> >   </element>
> > </test>
> > 
> > and when I do
> > 
> >         Document doc = builder.build(new File(filename));
> >         Element root = doc.getRootElement();
> >         System.out.println("hasMixedContent="+root.hasMixedContent());
> > 
> > I receive true, but there no mixed content in this xml.
> Yes it does. The root element has both character data (white space) and
> elements. It would only have no mixed content if a DTD was present, and
> specified that the element "test" could only have nested elements. JDOM
> is doing exactly the right thing.

Thank you and Jason Hunter, now I understand my error.
But when I try to solve it, I found another one.
I rewrite my xml like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE test [
  <!ELEMENT test (child) >
  <!ELEMENT child (#PCDATA| b)* >
    text <b>bold text</b> text

So now root element did not have mixed content and child element has it.
But when I try this:
        Element root = doc.getRootElement();
        Element elem = root.getChild("child");

I received false in both cases.
What wrong again?

Vyacheslav Pedak

More information about the jdom-interest mailing list