xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andra...@us.ibm.com
Subject A little help?
Date Wed, 16 Feb 2000 16:25:44 GMT
I'm attempting to validate the following document with the following dtd
using the xerces RevaliatingDOMParser.
I believe that the document is invalid but well formed. The parser corrects
for well formedness however ignores invalid elements.
If someone could give me a hint as  to what I am doing wrong I'd appreciate
it.

Thanks,
 Mike

DTD
<?xml version="1.0" encoding="UTF-8" ?>
<!ELEMENT Base_Element (child_One)?>
<!ELEMENT child_One (child_two)>
<!ELEMENT child_two (#PCDATA)>

XML Doc.
<?xml version="1.0"?>
<!DOCTYPE Base_Element SYSTEM "C:\ecdbtest\test.dtd">
<Base_Element>
  <child_One>
      <child_two>legal</child_two>
      <child_two>illegal</child_two>
  </child_One>
</Base_Element>

Parser Code.
public ValDomParse(String xmlFileName) {

      InputSource is = createInputSource( xmlFileName );
      depth = 0;
      if( is != null ) {
           RevalidatingDOMParser sp = new RevalidatingDOMParser();
           try {
                                                sp.setFeature("http://xml.org/sax/features/validation",true);
                                                if( sp.getFeature("http://xml.org/sax/features/validation")
== false )
                                                       System.out.println("Error Setting validation
feature");
                System.out.println("Parsing text");
                sp.parse( is );
                DocumentImpl doc = (DocumentImpl)sp.getDocument();
                NodeImpl node = (NodeImpl)doc.getDocumentElement();
                NodeImpl validNode = (NodeImpl)sp.validate( node );
                if( validNode != null ) {
                    System.out.println(" Error at node " + validNode.getNodeName()
                                            + " " + validNode.getNodeValue() );

                } else {
                    System.out.println("Document is Valid");
                }
                System.out.println("Completed Parsing Text");
           }
                                catch( SaxException se )
                                 .
                                 .

Mike Andrasak
IBM Global Services , Dept T39N-7
Tie: 532-8688
external: (914) 892-8688
IBM internal email: andrasak@ibmusm68
internet: andrasak@US.IBM.COM


Mime
View raw message