You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Shal Jain <sh...@intertechsys.com> on 2000/06/08 18:10:40 UTC

Re: namespace validating feature question


Hello

(If this is the wrong place to post a query, please direct me to the appropriate group/address)

I am trying to figure out how to get namespace validation to work.  
  
I am parsing an xml source using the included code stub
I expect to see an exception about undefined namespace.  Am I using the setValidating() & setValidation() calls correctly ?
or have I misunderstood how namespaces are used.

Here's the sample xml file which should throw an error since there does not exist a xmlns:its2 definition

[XML FILE]

<?xml version="1.0"?>
<its2:Parser name="abc"
        xmlns:its="http://www.intertechsys.com"
        type="OFX"
        src="http://abc.xyz">

 <its2:page name="first">
  <its:fill select="input[@type='text' and @name='inp1']" value="$var1"/>
  <its:fill select="input[@type='text' and @name='inp2']" value="$var2" />
 </its2:page>

</its2:Parser>


[JAVA CODE]

import org.w3c.dom.*;
import org.apache.xerces.parsers.*;
import org.xml.sax.InputSource;


public class builder extends DOMParser
{

// fileSpec points to a XML file
public static builder load(File fileSpec) {
  FileInputStream fi;
  try {
       try{
            fi = new FileInputStream(fileSpec);
           }
       catch (Exception e){
            System.out.println(fileSpec + " Rule File Not Found");
            return null;
       }
       try {
           builder.setFeature("http://xml.org/sax/features/namespaces", true);
           builder.setValidating(true);
           builder.setValidation(true);
       } 
       catch (Exception e) {
        System.out.print("Feature not supported");
        return null;
       }
       builder.parse( new InputSource(fi));

       Element rootElem = builder.getDocument().getDocumentElement();
       return this;
     }
  catch (Exception e){
   System.out.println(fileSpec + " Errors occurred in parsing: ...");
   e.printStackTrace();
   return null;
  }
 
}

}