I want to figure out any invalid elements or attributes in an xml. I have created a XSD file from the xml using Oxygen XML Editor. Now I am trying to parse & validate the xml using the XSD but my xml parses even if I add a new attribute. Below is the code. Now even though I add JUNKATTRIBUTE to my xml, it is getting parsed. Any suggestions?
http://www.ohchr.org。
public static boolean validatehelp(String helpData, helpReport helpReport) {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser parser = null;
spf.setNamespaceAware(true);
spf.setValidating(true);
FileReader fileReader = null;
try {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
fileReader = new FileReader("help_xsd.xsd");
spf.setSchema(sf.newSchema(new SAXSource(new InputSource(fileReader))));
//spf.setSchema(sf.newSchema(new Source[] {new StreamSource("help_xsd.xsd")}));
parser = spf.newSAXParser();
MySAXHandler handler = new MySAXHandler(configReport);
parser.parse(new InputSource(new StringReader(helpData)), handler);
return true;
}
My xml
<Help date="2020-06-24">
<product
id="en_US_SAN_15.0"
label="orange_16.0"
ProductName="orange 16.0 "
productName="orange 16.0 Pre"
productVersion="15.0"
baseUrl="http://help.stage.xyz.com/"
path="Help/en_US/"
ionId="orange_product_xyzlr"
ionCommentingAllowed="yes"
ionSiteArea="help"
ionRatingAllowed="yes"
ionRatingType="thumbs"
searchOptions="Community|xyz"
searchDefault="Community"
searchxyzRefinement="site=orange_V2_all"
="yes"
/>
<package
id="en_US_SAN_15.0_Using"
label="orange_16.0"
path="SAN/orange/15.0/Using"
description="SAN 15.0"
contextSensitivity="yes"
downloadContent="client.orange_V2_Using_en-us.zip"
downloadContentDefault="yes"
downloadPdf="orange_V4_help.pdf"
JUNKATTRIBUTE="JUNK"
/>
</Help>
<<>My XSD
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Help">
<xs:complexType>
<xs:sequence>
<xs:element ref="product"/>
<xs:element ref="package"/>
</xs:sequence>
<xs:attribute name="appId" />
<xs:attribute name="date" type="xs:date"/>
<xs:attribute name="locale" type="xs:NCName"/>
<xs:attribute name="pubId" />
<xs:attribute name="version" type="xs:decimal"/>
</xs:complexType>
</xs:element>
<xs:element name="product">
<xs:complexType>
<xs:attribute name="baseUrl" type="xs:anyURI"/>
<xs:attribute name="helpServiceUrl" type="xs:anyURI"/>
<xs:attribute name="id" type="xs:NCName"/>
<xs:attribute name="ionCommentingAllowed" type="xs:NCName"/>
<xs:attribute name="ionId" type="xs:NCName"/>
<xs:attribute name="ionRatingAllowed" type="xs:NCName"/>
<xs:attribute name="ionRatingType" type="xs:NCName"/>
<xs:attribute name="ionSiteArea" type="xs:NCName"/>
<xs:attribute name="label" />
<xs:attribute name="multidomain" type="xs:NCName"/>
<xs:attribute name="path" />
<xs:attribute name="productName" type="xs:NCName"/>
<xs:attribute name="productVersion" type="xs:NCName"/>
<xs:attribute name="searchxyzRefinement" />
<xs:attribute name="searchBlueprintRefinement" type="xs:NCName"/>
<xs:attribute name="searchCommunityRefinement" type="xs:NCName"/>
<xs:attribute name="searchDefault" type="xs:NCName"/>
<xs:attribute name="searchOptions" />
</xs:complexType>
</xs:element>
<xs:element name="package">
<xs:complexType>
<xs:attribute name="alias" />
<xs:attribute name="baseUrl" type="xs:anyURI"/>
<xs:attribute name="contextSensitivity" type="xs:NCName"/>
<xs:attribute name="deprecated" type="xs:NCName"/>
<xs:attribute name="description" />
<xs:attribute name="downloadContent" />
<xs:attribute name="downloadContentDefault" type="xs:NCName"/>
<xs:attribute name="downloadPdf" type="xs:NCName"/>
<xs:attribute name="helpmapPath" type="xs:anyURI"/>
<xs:attribute name="id" type="xs:NCName"/>
<xs:attribute name="label" />
<xs:attribute name="packageGenerator" type="xs:NCName"/>
<xs:attribute name="path" />
<xs:attribute name="urlParams" />
</xs:complexType>
</xs:element>
</xs:schema>