PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label xsd. Show all posts
Showing posts with label xsd. Show all posts

Thursday, August 11, 2022

[FIXED] What are the limits of the decimal type in XML Schema (XSD)?

 August 11, 2022     decimal, xml, xml-validation, xsd, xsd-validation     No comments   

Issue

What are the minimum and maximum acceptable values of the decimal type in XML Schema? (type="xs:decimal")?


Solution

XML Schema itself does not impose minimum and maximum values on xsd:decimal:

[Definition:] decimal represents arbitrary precision decimal numbers. The ·value space· of decimal is the set of the values i × 10^-n, where i and n are integers such that n >= 0.

[Contrast this with xsd:float, which corresponds to IEEE single-precision 32-bit floats.]

Implementations, on the other hand, may support limits to the range of xsd:decimal:

NOTE: All ·minimally conforming· processors ·must· support decimal numbers with a minimum of 18 decimal digits (i.e., with a ·totalDigits· of 18). However, ·minimally conforming· processors ·may· set an application-defined limit on the maximum number of decimal digits they are prepared to support, in which case that application-defined maximum number ·must· be clearly documented.

[For example, Xerces2-J uses java.math.BigDecimal; see How to get biggest BigDecimal value for answers on how big BigDecimal can be.]



Answered By - kjhughes
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, August 10, 2022

[FIXED] Why isn't xs:precisionDecimal part of the XSD1.1?

 August 10, 2022     decimal, precision, xml, xsd, xsd-1.1     No comments   

Issue

Although it is stated everywhere that xs:precisionDecimal belongs to the XML Schema 1.1 (see https://www.ibm.com/developerworks/xml/library/x-xml11pt1/ or https://www.w3.org/TR/xsd-precisionDecimal/), I cannot find any definition for xs:precisionDecimal under https://www.w3.org/2001/XMLSchema. If I'm clicking on the links under the XML Schema section, they are definitions for a lot of types (like int, double, string etc.) but not for precisionDecimal.

Where can I find the definition for xs:precisionDecimal and why is not part of https://www.w3.org/2001/XMLSchema?


Solution

At the time of the linked IBM DeveloperWorks article (2008), xs:precisionDecimal was planned for XSD 1.1 and was in the W3C XML Schema Definition Language (XSD) 1.1, W3C Working Draft 20 June 2008.

By W3C Candidate Recommendation 21 July 2011, xs:precisionDecimal was removed:

The precisionDecimal datatype has been removed since there does not seem to be sufficient consensus in the community for its retention.

It is, as you've observed, not part of the current recommendation, W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes, W3C Recommendation 5 April 2012.



Answered By - kjhughes
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, July 30, 2022

[FIXED] How to validate XML against XSD 1.1 in Java?

 July 30, 2022     java, validation, xml, xsd, xsd-1.1     No comments   

Issue

What is the best way to validate XML files against XML Schema 1.1 in Java?

I took the code from this tutorial and changed the line where it looks up the factory to use XML Schema 1.1 as I have seen in this code example from the Xerces FAQ.

This is my code:

import java.io.File;
import java.io.IOException;
import javax.xml.transform.Source;
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 XSDValidator {
    private static void validateFile(File xmlFile, File xsdFile) throws SAXException, IOException
    {
        // 1. Lookup a factory for the W3C XML Schema language
        SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/XML/XMLSchema/v1.1");
        // SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

        // 2. Compile the schema.
        File schemaLocation = xsdFile;
        Schema schema = factory.newSchema(schemaLocation);

        // 3. Get a validator from the schema.
        Validator validator = schema.newValidator();

        // 4. Parse the document you want to check.
        Source source = new StreamSource(xmlFile);

        // 5. Check the document
        try
        {
            validator.validate(source);
            System.out.println(xmlFile.getName() + " is valid.");
        }
        catch (SAXException ex)
        {
            System.out.println(xmlFile.getName() + " is not valid because ");
            System.out.println(ex.getMessage());
        }
    }
}

The code throws this exception:

java.lang.IllegalArgumentException: No SchemaFactory that implements the schema language specified by: http://www.w3.org/XML/XMLSchema/v1.1 could be loaded

As I see it I have exactly the same imports as the code snippet in the Xerces FAQ. I even tried to add Xerces to my Maven dependencies but that didn't help either.

Cheers :)


Solution

I don't think you can use the JAXP service mechanism to search for an XSD 1.1 processor. Load Saxon or Xerces in the normal way, and then enable XSD 1.1 processing. For Saxon this is done using

SchemaFactory.setProperty("http://saxon.sf.net/feature/xsd-version", "1.1")

UPDATE 2021-09-04 In recent Saxon releases, XSD 1.1 is the default, and no special property needs to be set to enable it.



Answered By - Michael Kay
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing