Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8055735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:29:10+00:00 2026-06-05T08:29:10+00:00

After reading this I’ve been trying to implement a custom datatype to be used

  • 0

After reading this I’ve been trying to implement a custom datatype to be used by a RelaxNG XML validator (Jing). I’ve successfully ran the example implementation which is provided by Jing (they call it datatype-sample) through command line but I keep failing to do it from java code.

From command line (windows):

> set CLASSPATH=path\to\jing-20091111\bin\jing.jar;path\to\jing-20091111\sample\datatype\datatype-sample.jar
> cd path\to\jing-20091111\sample\datatype
> java com.thaiopensource.relaxng.util.Driver datatype-sample.rng valid.xml

Validation was performed without any problems. But now I’m trying to use the same datatype library from the following java code:

package rngdatatype;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.xml.sax.SAXException;

public class Main {

    public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, SAXException, IOException {
        // make sure our jars are on classpath
        System.out.println("Classpath: " + System.getProperty("java.class.path"));

        // args
        String rng = args[0];
        String xml = args[1];
        File rngFile = new File(rng);
        File xmlFile = new File(xml);

        // setup rng validator through JAXP
        System.setProperty(SchemaFactory.class.getName() + ":" + XMLConstants.RELAXNG_NS_URI, "com.thaiopensource.relaxng.jaxp.XMLSyntaxSchemaFactory");
        SchemaFactory rngSchemaFactory = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);

        // obtain a schema object
        InputStreamReader rngReader = new InputStreamReader(new FileInputStream(rngFile), "UTF-8");
        Schema schema = rngSchemaFactory.newSchema(new StreamSource(rngReader));

        // validate using schema based validator
        Validator validator = schema.newValidator();
        InputStreamReader xmlReader = new InputStreamReader(new FileInputStream(xmlFile), "UTF-8");
        validator.validate(new StreamSource(xmlReader));
    }
}

With first argument being a path to a file with the following content:

<element name="balancedString"
   xmlns="http://relaxng.org/ns/structure/1.0"
   datatypeLibrary="http://www.thaiopensource.com/relaxng/datatypes/sample">
  <data type="balancedString"/>
</element>

And the second argument being a path to a file with the following content:

<balancedString>foo(bar(baz))</balancedString>

Which gives me the following output:

Classpath: path\to\RNGDataType\lib\datatype-sample.jar;path\to\RNGDataType\lib\jing.jar;path\to\RNGDataType\build\classes;path\to\RNGDataType\src
Exception in thread "main" org.xml.sax.SAXParseException: datatype library "http://www.thaiopensource.com/relaxng/datatypes/sample" not recognized
...

This clearly indicates that the datatype could not be resolved. The only requirement for this to work (have both jing.jar and datatype-sample.jar on classpath) has been satisfied as far as I can tell. So what am I doing wrong?

P.S: for the above code to work you have to put jing.jar and datatype-sample.jar on your classpath AND provide arguments to it where the first one is path to datatype-sample.rng and the second one is path to valid.xml or invalid.xml. All of these are distributed with Jing.

Edit1: the above program also doesn’t work outside my IDE when ran as a JAR (java -jar) with a proper MANIFEST.MF file. Also doesn’t work when classpath is set manually (java -classpath). So I suspect something is wrong with the actual code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:29:12+00:00Added an answer on June 5, 2026 at 8:29 am

    It appears that using custom datatype libraries via Jing through JAXP API is broken somehow. It doesn’t work even though it should. Perhaps some additional properties need to be set somewhere and I’m just not aware of this.

    So I guess I found a workaround by mimicking Jing’s com.thaiopensource.relaxng.util.Driver and therefore using Jing’s own API to perform the validation. Note that doing so restricts your code so it works only with Jing.

    package rngdatatype;
    
    import com.thaiopensource.validate.SchemaReader;
    import com.thaiopensource.validate.ValidationDriver;
    import com.thaiopensource.validate.auto.AutoSchemaReader;
    import java.io.File;
    import java.io.IOException;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    
    public class JingApi {
    
        public static void main(String[] args) throws SAXException, IOException {
            String rng = args[0];
            String xml = args[1];
            File rngFile = new File(rng);
            File xmlFile = new File(xml);
    
            SchemaReader sr = new AutoSchemaReader();
            ValidationDriver driver = new ValidationDriver(sr);
            InputSource inRng = ValidationDriver.fileInputSource(rngFile);
            inRng.setEncoding("UTF-8");
            driver.loadSchema(inRng);
            InputSource inXml = ValidationDriver.fileInputSource(xmlFile);
            inXml.setEncoding("UTF-8");
            driver.validate(inXml);
        }
    }
    

    This enables you to validate your XML files from java code based on a RNG schema which uses custom datatype libraries. Note that the Diver class I mentioned earlier cannot be used directly.

    The above program uses the same classpath and arguments as the example in my own question.

    Edit1 ———————————————

    After fiddling around a bit more I found the property that needs to be set in order to get my JAXP example to play along with Jing when using custom datatype libraries. Simply add the following line after you obtain an instance of SchemaFactory:

    rngSchemaFactory.setProperty("http://relaxng.org/properties/datatype-library-factory", new org.relaxng.datatype.helpers.DatatypeLibraryLoader());
    

    This is a much more elegant solution that using Jing native API.

    /Edit1 ——————————————–

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading this post regarding the use ECC to implement the hashing using aa
I'm trying to understand how to use Type Converters after reading this answer to
I am trying to learn JavaScript. After reading this page: What does ':' (colon)
I am trying to learn how to use rand_r, and after reading this question
After reading this post I kinda felt in the same position as the guy
After reading this article on thedailywtf.com, I'm not sure that I really got the
After reading this: http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#how-to-use-it I came to the conclusion that it is not valid
After reading this question , i saw the answer by Naveen containing a link
After reading this article http://lukast.mediablog.sk/log/?p=155 I decided to use mingw on linux to compile
After reading this post on Stackoverflow Google plus popup box when hovering over thumbnail?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.