We have noticed a few users posting problems with validation when dealing with files that make use of a schema. We have looked into this and for almost all the cases reported the problem was the location of the Schema is not specified, so it is attempted to be resolved from the "root" directory, which in the case of a web project is the WebRoot, in the case of a Java Project, is the current directory.
Let's look at an Example from using Drools (http://drools.org)
| Code: |
<?xml version="1.0"?>
<rule-set name="CalculatorWorker"
xmlns="http://drools.org/rules"
xmlns:java="http://drools.org/semantics/java"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/rules rules.xsd
http://drools.org/semantics/java java.xsd">
<java:import>java.lang.String</java:import>
<java:import>com.csfb.fao.clr.calc.rules.Input</java:import>
<!--
<rule name="blank" salience="-10">
<parameter identifier="input">
<class>java.lang.String</class>
</parameter>
<java:condition>1==1</java:condition>
<java:consequence>
System.out.println("Blank");
</java:consequence>
</rule>
-->
<rule name="Portfolio_Participation_SELL_Exists" salience="-1">
<parameter identifier="input">
<class>Input</class>
</parameter>
<java:condition>input.getFacilLenderIndic().equals("P") || input.getFacilLenderIndic().equals("M")</java:condition>
<java:condition>input.getPortfolioPartSellExists().equals("undefined")</java:condition>
<java:consequence>
//System.out.println("Portfolio_Participation_SELL_Exists");
input.setPortfolioPartSellExists("Y");
//System.out.println("Sell indicator: " + input.getPortfolioPartSellExists() + " on " + input);
drools.modifyObject(input);
</java:consequence>
</rule>
<rule name="Portfolio_Participation_SELL_Does_NOT_Exists" salience="-1">
<parameter identifier="input">
<class>Input</class>
</parameter>
<java:condition>input.getFacilLenderIndic().equals("B")</java:condition>
<java:condition>input.getPortfolioPartSellExists().equals("undefined")</java:condition>
<java:consequence>
//System.out.println("Portfolio_Participation_SELL_Exists");
input.setPortfolioPartSellExists("N");
//System.out.println("Sell indicator: " + input.getPortfolioPartSellExists() + " on " + input);
drools.modifyObject(input);
</java:consequence>
</rule>
<rule name="Risk_Ost_2">
<parameter identifier="input">
<class>com.csfb.fao.clr.calc.rules.Input</class>
</parameter>
<java:condition>input.getOstCount() > 0 </java:condition>
<java:condition>!input.getOtsdTypeCategoryCd().equals("LN") </java:condition>
<java:condition>input.getOtsdTypeCategoryCd().equals("LC") </java:condition>
<java:condition>input.getOpsCount() > 0 </java:condition>
<java:condition>input.getLocIssueFirmInd().equals("N") </java:condition>
<java:condition>input.getPortfolioPartSellExists().equals("Y")</java:condition>
<java:consequence>
System.out.println("Calculate RISK_OST_2");
</java:consequence>
</rule>
<rule name="Risk_Ost_3">
<parameter identifier="input">
<class>com.csfb.fao.clr.calc.rules.Input</class>
</parameter>
<!-- Facility has outstanding -->
<java:condition>input.getOstCount() > 0 </java:condition>
<!-- Outstanding type is not Loan -->
<java:condition>!input.getOtsdTypeCategoryCd().equals("LN") </java:condition>
<!-- Outstanding type is Letter of Credit -->
<java:condition>input.getOtsdTypeCategoryCd().equals("LC") </java:condition>
<!-- Outstanding has OPSs -->
<java:condition>input.getOpsCount() > 0 </java:condition>
<!-- LC is not CSFB Issue (Fronted) -->
<java:condition>input.getLocIssueFirmInd().equals("N") </java:condition>
<!-- Portfolio participation SELL does NOT exists -->
<java:condition>input.getPortfolioPartSellExists().equals("N")</java:condition>
<java:consequence>
System.out.println("Calculate RISK_OST_3");
</java:consequence>
</rule>
</rule-set>
|
The part we care about here is the header:
| Code: |
<rule-set name="CalculatorWorker"
xmlns="http://drools.org/rules"
xmlns:java="http://drools.org/semantics/java"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/rules rules.xsd
http://drools.org/semantics/java java.xsd">
|
Notice the xs:schemaLocation tag:
| Code: |
xs:schemaLocation="http://drools.org/rules rules.xsd
http://drools.org/semantics/java java.xsd"
|
The format for these entries is:
<URI> <URL to Schema>
Since there is no location given for the rules.xsd or java.xsd files, the validator is checking the root directory and failing. Now if you use your browser to open up the links: http://drools.org/rules
You'll notice they spit back the contents of these files respectively, so really the location of the schema files are these URIs (NOTE: The URIs in this example happen to be valid URLs, they don't have to be though) so we have two choices now:
* Download the contents of the two pages and place them into new files rules.xsd and java.xsd which go into the root directory
* Use the URIs themselves as the URLs to the schema files.
I will show what #2 looks like:
| Code: |
xs:schemaLocation="http://drools.org/rules http://drools.org/rules
http://drools.org/semantics/java http://drools.org/semantics/java"
|
This looks a little odd, but does the trick. Don't forget to save and then right-click-> Validate XML on the file, viola, no more errors. |