Decimal value is coming as 0E-8
we are validating XML with XSD in java 1.8 and web logic 12c,But we are facing 0E-8 is not a valid value for decimal
Below is my XML:
<?xml version="1.0" encoding="UTF-8"?> <isns:Envelope xmlns:isns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pkp-core="http://tracx.de/pkp/interfaces/core/1.0" xmlns:pkp-msg="http://tracx.de/pkp/interfaces/msg/1.0"> <isns:Header/> <isns:Body> <pkp-msg:ABC> <pkp-msg:test> <pkp-core:oops> <pkp-core:XYZ>0.00000000</pkp-core:XYZ> <pkp-core:billi>period</pkp-core:bill> <pkp-core:check>0.90225</pkp-core:check> </pkp-core:oops> </pkp-msg:test> </pkp-msg:ABC> </isns:Body> </isns:Envelope>
piece of java code :
javax.xml.validation.Validator validator = schema.newValidator(); validator.setErrorHandler(new EUBatchValidationHandler()); validator.validate(source);
Unable to Reproduce
This is not an answer, but is written as such, so it can include a Minimal, Reproducible Example.
The following code has been tested on:
- OpenJDK jdk1.7.0_75
- Oracle jdk1.8.0_181
- OpenJDK jdk-11.0.2
- OpenJDK jdk-14
The code produce the same output on all 4.
import java.io.StringReader; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import org.w3c.dom.Document; import org.xml.sax.InputSource; public class Test { public static void main(String[] args) throws Exception { String xml = "<ABC>\n" + " <XYZ>0.00000000</XYZ>\n" + "</ABC>"; DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder domBuilder = domFactory.newDocumentBuilder(); Document document = domBuilder.parse(new InputSource(new StringReader(xml))); System.out.println("XYZ = " + document.getElementsByTagName("XYZ").item(0).getTextContent()); String xsd = "<schema xmlns=\"http://www.w3.org/2001/XMLSchema\">\n" + " <element name=\"ABC\">\n" + " <complexType>\n" + " <sequence>\n" + " <element name=\"XYZ\" type=\"decimal\" />\n" + " </sequence>\n" + " </complexType>\n" + " </element>\n" + "</schema>"; SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(new StreamSource(new StringReader(xsd))); Validator validator = schema.newValidator(); validator.validate(new DOMSource(document)); System.out.println("Validation successful"); } }
Output
XYZ = 0.00000000 Validation successful