already defined error when converting xsd to java - java

I want to translate a complicated set of xsd files into Java/Hibernate entities. Towards that end,
I downloaded version 2.2.7 of JAXB from this link. I unzipped the file, opened cmd.exe, navigated to the directory of the create-marshal sample, ran ant compile to confirm everything works, then ran ant clean to eliminate the results to return everything to starting conditions.
The problem came when I tried to use a different xsd file as the input for the create-marshal sample. Specifically, I am getting an error when the xsd file distinguishes between data structures by changing the value of an attribute of the same tag type. The create-marshal sample gives the following error in that case:
[ERROR] 'POCD_MT000040.InfrastructureRoot.typeId' is already defined
[xjc] line 54 of file:/C:/Temp/jaxb/apps/create-marshal/POCD_MT000040_SDTC.xsd
The error repeats again and again, once for every time that the value of the attribute is re-assigned for a different data structure definition. How can I resolve this error?
Here are the first few iterations of the data structure in the xsd file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema targetNamespace="urn:the-publisher:v3"
xmlns:mif="urn:the-publisher:v3/mif"
xmlns="urn:the-publisher:v3"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
xmlns:sdtc="urn:the-publisher:sdtc">
<xs:annotation>
<xs:documentation>Manually edited to add Schema Extensions, July 2012</xs:documentation>
<xs:documentation>Generated using schema builder version 2.0. Stylesheets: RoseTreeToMIFStaticModel.xsl version: 1.1 StaticMifToXsd.xsl version 2.0</xs:documentation>
</xs:annotation>
<xs:complexType name="POCD_MT000040.InfrastructureRoot.typeId">
<xs:complexContent>
<xs:restriction base="II">
<xs:attribute name="root" type="uid"
use="required"
fixed="2.16.840.1.113883.1.3"/>
<xs:attribute name="extension" type="st"
use="required"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="POCD_MT000040.Act">
<xs:sequence>
<xs:element name="realmCode" type="CS"
minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="typeId"
type="POCD_MT000040.InfrastructureRoot.typeId"
minOccurs="0"/>
<xs:element name="templateId" type="II"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="id" type="II" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="code" type="CD"/>
<xs:element name="text" type="ED" minOccurs="0"/>
<xs:element name="statusCode" type="CS"
minOccurs="0"/>
<xs:element name="effectiveTime" type="IVL_TS"
minOccurs="0"/>
<xs:element name="priorityCode" type="CE"
minOccurs="0"/>
<xs:element name="languageCode" type="CS"
minOccurs="0"/>
<xs:element name="subject"
type="POCD_MT000040.Subject" minOccurs="0"/>
<xs:element name="specimen"
type="POCD_MT000040.Specimen" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="performer"
type="POCD_MT000040.Performer2" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="author"
type="POCD_MT000040.Author" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="informant"
type="POCD_MT000040.Informant12"
minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="participant"
type="POCD_MT000040.Participant2"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="entryRelationship"
type="POCD_MT000040.EntryRelationship"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="reference"
type="POCD_MT000040.Reference"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="precondition"
type="POCD_MT000040.Precondition"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="nullFlavor"
type="NullFlavor" use="optional"/>
<xs:attribute name="classCode"
type="x_ActClassDocumentEntryAct" use="required"/>
<xs:attribute name="moodCode" type="x_DocumentActMood"
use="required"/>
<xs:attribute name="negationInd" type="bl"
use="optional"/>
</xs:complexType>
<xs:complexType name="POCD_MT000040.AssignedAuthor">
<xs:sequence>
<xs:element name="realmCode" type="CS"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="typeId"
type="POCD_MT000040.InfrastructureRoot.typeId"
minOccurs="0"/>
<xs:element name="templateId" type="II"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="id" type="II"
maxOccurs="unbounded"/>
<xs:element name="code" type="CE" minOccurs="0"/>
<xs:element name="addr" type="AD"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="telecom" type="TEL"
minOccurs="0" maxOccurs="unbounded"/>
<xs:choice>
<xs:element name="assignedPerson"
type="POCD_MT000040.Person" minOccurs="0"/>
<xs:element name="assignedAuthoringDevice"
type="POCD_MT000040.AuthoringDevice"
minOccurs="0"/>
</xs:choice>
<xs:element name="representedOrganization"
type="POCD_MT000040.Organization" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="nullFlavor"
type="NullFlavor" use="optional"/>
<xs:attribute name="classCode"
type="RoleClassAssignedEntity"
use="optional" fixed="ASSIGNED"/>
</xs:complexType>
Here are the corresponding first few iterations of the error message:
Build sequence for target(s) `compile' is [compile]
Complete build sequence is [compile, javadoc, clean, run, ]
compile:
[echo] Compiling the schema...
[mkdir] Created dir: C:\Temp\jaxb\apps\create-marshal\gen-src
[mkdir] Created dir: C:\Temp\jaxb\apps\create-marshal\gen-src\primer\po
[xjc] build id of XJC is 2.2.7
[xjc] Checking timestamp of C:\Temp\jaxb\apps\create-marshal\POCD_MT000040_SDTC.xsd
[xjc] the last modified time of the inputs is 1409957672397
[xjc] the last modified time of the outputs is -9223372036854775808
[xjc] Compiling file:/C:/Temp/jaxb/apps/create-marshal/POCD_MT000040_SDTC.xsd
[xjc] [ERROR] 'POCD_MT000040.InfrastructureRoot.typeId' is already defined
[xjc] line 54 of file:/C:/Temp/jaxb/apps/create-marshal/POCD_MT000040_SDTC.xsd
[xjc]
[xjc] [ERROR] (related to above error) the first definition appears here
[xjc] line 46 of file:/C:/Temp/jaxb/apps/create-marshal/infrastructure/cda/POCD_MT000040_SDTC.xsd
[xjc]
[xjc] [ERROR] 'POCD_MT000040.Act' is already defined
[xjc] line 81 of file:/C:/Temp/jaxb/apps/create-marshal/POCD_MT000040_SDTC.xsd
[xjc]
.....the same error repeats many more times, once for each repetition of xs:complexType
[xjc] failure in the XJC task. Use the Ant -verbose switch for more details
compile: duration 2 seconds
BUILD FAILED
C:\Temp\jaxb\apps\create-marshal\build.xml:29: unable to parse the schema. Error messages should have been provided
at com.sun.tools.xjc.XJC2Task._doXJC(XJC2Task.java:520)
at com.sun.tools.xjc.XJC2Task.doXJC(XJC2Task.java:457)
at com.sun.tools.xjc.XJC2Task.execute(XJC2Task.java:380)
at com.sun.istack.tools.ProtectedTask.execute(ProtectedTask.java:103)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Here is the ant build file:
<?xml version="1.0" standalone="yes"?>
<!-- Copyright 2004 Sun Microsystems, Inc. All rights reserved. -->
<project basedir="." default="run">
<description>This sample application demonstrates how to use the ObjectFactory class to create a Java content tree from scratch and marshal it to XML data. It also demonstrates how to add content to a JAXB List property.</description>
<record name="build.log" loglevel="verbose" action="start"/>
<property name="jaxb.home" value="../.." />
<path id="classpath">
<pathelement path="src" />
<pathelement path="classes" />
<pathelement path="schemas" />
<fileset dir="${jaxb.home}" includes="lib/*.jar" />
</path>
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath refid="classpath" />
</taskdef>
<!--compile Java source files-->
<target name="compile" description="Compile all Java source files">
<echo message="Compiling the schema..." />
<mkdir dir="gen-src" />
<mkdir dir="gen-src/primer/po" />
<xjc schema="POCD_MT000040_SDTC.xsd" package="primer.po" destdir="gen-src">
<produces dir="gen-src/primer/po" includes="**/*.java" />
</xjc>
<echo message="Compiling the java source files..." />
<mkdir dir="classes" />
<javac destdir="classes" debug="on">
<src path="src" />
<src path="gen-src" />
<classpath refid="classpath" />
</javac>
</target>
<target name="run" depends="compile" description="Run the sample app">
<echo message="Running the sample application..." />
<java classname="Main" fork="true">
<classpath refid="classpath" />
</java>
</target>
<target name="javadoc" description="Generates javadoc" depends="compile">
<echo message="Generating javadoc..." />
<mkdir dir="docs/api" />
<javadoc sourcepath="gen-src" destdir="docs/api" windowtitle="create-marshal (formerly SampleApp3)" useexternalfile="yes">
<fileset dir="." includes="gen-src/**/*.java" excludes="**/impl/**/*.java" />
</javadoc>
</target>
<target name="clean" description="Deletes all the generated artifacts.">
<delete dir="docs/api" />
<delete dir="gen-src" />
<delete dir="schemas" />
<delete dir="classes" />
</target>
</project>

The error you are reporting indicates that, somehow, ant has been instructed to read the same XML Schema definitions twice. Indeed, the error message says that one definition is in
C:\Temp\jaxb\apps\create-marshal\POCD_MT000040_SDTC.xsd
and the other one was found in
...\create-marshal\infrastructure\cda\POCD_MT000040_SDTC.xsd
You should clean up the file tree below create-marshal. You need one of these two, and, relatived to this file, the ones included by it, e.g.:
..\coreschemas\datatypes.xsd
..\coreschemas\voc.xsd
..\coreschemas\NarrativeBlock.xsd
Finally, datatypes-base.xsd must be in the same folder as these three, as it is included by datatypes.xsd.
But when you have tidied this up, you'll run into another problem, at least with the JAXB that comes with JDK 1.8. This is a bug in xjc, triggered by the (unintentional) duplication of a field "id" in a number of complex types, e.g., here:
<xs:complexType name="POCD_MT000040.ObservationMedia">
...
<xs:element name="id" type="II" minOccurs="0" maxOccurs="unbounded"/>
...
<xs:attribute name="ID" type="xs:ID"/>
The mapping of XML Schema names to Java names is defined in the JAXB spec, and, no matter how a clash is produced, this should result in an error message (not a stack dump, as it happens).
You have to handle this problem (bug or no bug) using customization with a JAXB binding file. Here's one (let'S call it rename.xjb), renaming the field matching #ID in POCD_MT000040.ObservationMedia to `xsid
FIXES ALL NAME CLASHES id vs. ID
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<bindings schemaLocation="./POCD_MT000040.xsd" node="/xs:schema">
<bindings node="//xs:complexType[#name='POCD_MT000040.ObservationMedia']/xs:attribute[#name='ID']">
<property name="xsid"/>
</bindings>
</bindings>
<bindings schemaLocation="./POCD_MT000040.xsd" node="/xs:schema">
<bindings node="//xs:complexType[#name='POCD_MT000040.RegionOfInterest']/xs:attribute[#name='ID']">
<property name="xsid"/>
</bindings>
</bindings>
<bindings schemaLocation="./POCD_MT000040.xsd" node="/xs:schema">
<bindings node="//xs:complexType[#name='POCD_MT000040.Section']/xs:attribute[#name='ID']">
<property name="xsid"/>
</bindings>
</bindings>
</bindings>
You have to add the bindings file to the xjc invocation. In ant, this would be the #binding of <xjc>:
<xjc schema="POCD_MT000040_SDTC.xsd" binding="rename.xjb" ...

Related

isSet methods not generated using jaxb2-basics simplify plugin

I have a schema with two elements within a <xs:choice/> block, as per the following fragment:
<xs:complexType name="POCD_MT000040.Component2">
<xs:sequence>
<xs:element name="realmCode" type="CS" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="typeId" type="POCD_MT000040.InfrastructureRoot.typeId" minOccurs="0"/>
<xs:element name="templateId" type="II" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice>
<xs:element name="nonXMLBody" type="POCD_MT000040.NonXMLBody"/>
<xs:element name="structuredBody" type="POCD_MT000040.StructuredBody"/>
</xs:choice>
</xs:sequence>
<xs:attribute name="nullFlavor" type="NullFlavor" use="optional"/>
<xs:attribute name="typeCode" type="ActRelationshipHasComponent" use="optional" fixed="COMP"/>
<xs:attribute name="contextConductionInd" type="bl" use="optional" fixed="true"/>
</xs:complexType>
This is part of the HL7/CDA specification schemas, by the way.
Well, I am using maven-jaxb2-plugin to generate the Java classes, with a touch of the jaxb2-basics plugin to simplify complex elements, like nonXMLBody and structuredBody. Let's say I have a bindings file with the following contents:
<jxb:bindings
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
jxb:extensionBindingPrefixes="xjc simplify"
version="2.1">
<jxb:globalBindings
typesafeEnumMaxMembers="1000"
generateMixedExtensions="true"
generateIsSetMethod="true"
choiceContentProperty="true">
<xjc:serializable uid="1" />
</jxb:globalBindings>
<jxb:bindings schemaLocation="xsd/POCD_MT000040.xsd">
<jxb:bindings node="xs:complexType[#name='POCD_MT000040.Component2']//xs:choice">
<simplify:as-element-property />
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
The attributes are generated as expected:
protected POCDMT000040NonXMLBody nonXMLBody;
protected POCDMT000040StructuredBody structuredBody;
However, although I am using generateIsSetMethod="true" in the global bindings, the methods isSetNonXMLBody ( ) and isSetStructuredBody ( ) are not being generated at all. The equivalent methods for the rest of the attributes are present, though, like isSetTypeId ( ).
Am I missing any option I should know of to generate these methods in the aforementioned elements?

XSD "property already defined"

I'm trying to use jaxb to compile some Veracode provided .xsd files
the "detailedreport.xsd" is throwing this error:
[ERROR] Property "Vulnerabilities" is already defined. Use <jaxb:property> to resolve this conflict.
line 930 of file:detailedreport.xsd
[ERROR] The following location is relevant to the above error
line 936 of detailedreport.xsd
when I look at the XSD file, I see that Vulnerabilities is both an attr and a type:
<xs:complexType name="Component">
<xs:annotation>
<xs:documentation>
The element describe the details of vulnerable component.
* file_paths: File paths of the component.
-----> * vulnerabilities : Vulnerabilities of the component.
* violated_policy_rules: Violated policy rules of the component.
* component_id: The id of the component.
* file_name: File name of the component.
-----> * vulnerabilities: Number of vulnerabilities available in the component.
* max_cvss_score: Max cvss_score of the component.
* library: Library name of the component.
* version: Version of the component.
* vendor: Vendor name of the component.
* description: Description about component.
* blacklisted: Component's blacklisted status.
* new: Component added newly.
* added_date: Component's added_date.
* component_affects_policy_compliance: COmponent's policy violation status.
* licenses: Contains license details of the component.
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="file_paths" minOccurs="0" maxOccurs="1" type="tns:FilePathList"/>
<xs:element name="licenses" minOccurs="0" maxOccurs="1" type="tns:LicenseList"/>
-----> <xs:element name="vulnerabilities" minOccurs="0" maxOccurs="1" type="tns:VulnerabilityList" />
<xs:element name="violated_policy_rules" minOccurs="0" maxOccurs="1" type="tns:ViolatedRuleList" />
</xs:sequence>
<xs:attribute name="component_id" type="xs:string" use="required"/>
<xs:attribute name="file_name" type="xs:string" use="required"/>
<xs:attribute name="sha1" type="xs:string" use="required"/>
-----> <xs:attribute name="vulnerabilities" type="xs:integer" use="required"/>
<xs:attribute name="max_cvss_score" type="xs:string" use="required"/>
<xs:attribute name="library" type="xs:string" use="required"/>
<xs:attribute name="version" type="xs:string" use="required"/>
<xs:attribute name="vendor" type="xs:string" use="required"/>
<xs:attribute name="description" type="xs:string" use="required"/>
<xs:attribute name="blacklisted" type="xs:string"/>
<xs:attribute name="new" type="xs:string"/>
<xs:attribute name="added_date" type="xs:string"/>
<xs:attribute name="component_affects_policy_compliance" type="xs:string"/>
</xs:complexType>
here's the xsd they publish: https://analysiscenter.veracode.com/resource/detailedreport.xsd
from what I can figure out, I need to create a detailedreport.xjb file and (as the output states) setup a <jaxb:property> to convert the vulnerabilities integer attribute into something like vulnerabilityCount.
I created detailedreport.xjb:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<!-- Used to avoid the duplicate element/attribute name conflict -->
<jaxb:bindings node="//xsd:attribute[#name='vulnerabilities']">
<jaxb:property name="vulnerabilityCount"/>
</jaxb:bindings>
</jaxb:bindings>
but my xpath is wrong:
[ERROR] XPath evaluation of "//xsd:attribute[#name='vulnerabilities']" results in empty target node
line 10 of file: detailedreport.xjb
am I even on the right path
any xpath help is appreciated
One more bindins element referencing schema location should be provided:
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jxb:extensionBindingPrefixes="xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation="http://java.sun.com/xml/ns/jaxb
http://java.sun.com/xml/ns/jaxb"
>
<jxb:bindings schemaLocation="PATH_TO_THE_SCHEMA" node="/xs:schema">
<jxb:bindings node="//xs:attribute[#name='vulnerabilities']">
<jxb:property name="vulnerabilityCount"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
Path can be relative to xjb file, e.g.: schemaLocation="../detailedreport.xsd"

JAXB Unmarshalling of XML into HashMap

I have a complex XML Structure as below which needs to be unmarshalled:
<abc>
<pqr>
<attribute>name</attribute>
<entry>
<priorityKey>
<class>123</class>
<reason>abc</reason>
</prioritykey>
<priority> 1 </priority>
</entry>
<entry>
<prioritykey>
<class>456</class>
<reason>abc1</reason>
</prioritykey>
<priority>2</priority>
</entry>
</pqr>
<pqr>
'''
'''
</pqr>
</abc>
abc is the root node. It can have multiple pqr elements. Each pqr element has one attribute node and multiple entry nodes. So I believe it will be of type HashMap(entry,attribute).
Each entry in turn has prioritykey and priority which I believe will be of type HashMap (prioritykey,priority).
Need to unmarshall this xml but not getting how to configure the XMLAdapter
Here, create the contract first. I created one as part of my learning process...
<xs:element name="abc" type="abcType" />
<xs:complexType name="abcType">
<xs:sequence>
<xs:element name="pqr" type="pqrType" minOccurs="1"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="pqrType">
<xs:sequence>
<xs:element name="attribute" type="xs:string" minOccurs="1"
maxOccurs="1" />
<xs:element name="entry" type="entryType" minOccurs="1"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="entryType" >
<xs:sequence>
<xs:element name="priorityKey" type="priorityKeyType"
minOccurs="1" maxOccurs="1" />
<xs:element name="priority" type="xs:int" minOccurs="1"
maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="priorityKeyType">
<xs:sequence>
<xs:element name="class" type="xs:int" minOccurs="1"
maxOccurs="1" />
<xs:element name="reason" type="xs:string" minOccurs="1"
maxOccurs="1" />
</xs:sequence>
</xs:complexType>
Copy and save this in an fileName.xsd file.
Now, generate JAXB classes or artifacts. If you are using an IDE, then this is simple. Click on the fileName.xsd file and you should get some option to generate JAXB artifacts. Otherwise, you can always use jaxb-xjc.jar present in the lib present in the JAXB download.
Command for the same - java -jar jaxb-xjc.jar fileName.xsd.
As the artifacts are in place, you can use them to unmarshall the xml content in question.

Error while generating JAXB model from xsd in eclipse

I am trying to generate JAXB model from the following xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://abc.com/mmm/trt" attributeFormDefault="unqualified"
elementFormDefault="qualified">
<xs:annotation>
<xs:documentation>Schema for Cache Refresh Event.
</xs:documentation>
</xs:annotation>
<xs:simpleType name="cacheCode">
<xs:restriction base="xs:string">
<xs:enumeration value="BUSINESS_RULE" />
<xs:enumeration value="USER" />
</xs:restriction>
</xs:simpleType>
<xs:element name="cacheRefreshEvent">
<xs:complexType>
<xs:sequence>
<xs:element name="cacheCode" type="cacheCode" minOccurs="1"
maxOccurs="1" />
<xs:element name="entityRefId" type="xs:string" minOccurs="0"
maxOccurs="20" />
<xs:element name="cacheRefreshDate" type="xs:dateTime"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
But, it is giving me the following error, which i got in Eclipse console
parsing a schema...
[ERROR] src-resolve.4.1: Error resolving component 'cacheCode'. It was detected that 'cacheCode' has no namespace, but components with no target namespace are not referenceable from schema document 'file:/F:/Sprint6/cache/src/main/resources/CacheRefreshEvent.xsd'. If 'cacheCode' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'cacheCode' has no namespace, then an 'import' without a "namespace" attribute should be added to 'file:/F:/Sprint6/cache/src/main/resources/CacheRefreshEvent.xsd'.
line 18 of file:/F:/Sprint6/cache/src/main/resources/CacheRefreshEvent.xsd
Failed to parse a schema.
Please help.
Remove this extra namespace attribute targetNamespace="http://www.hcentive.com/mea/trr"
OR add this xmlns="http://www.hcentive.com/mea/trr"
Both solutions will work :)
For you reference targetnamespace-and-xmlns

how to add validation in xsd for blank spaces

i have created basic xsd successfully however I want to add restriction for the element that it should be present and contains atleast one character. it also has 4 attributes. i am facing problem in adding restriction since I can not use simple type as the element has attributes.
Please suggest something
thanks in advance
Added XSD data posted by OP in comments (sic)
<xs:element name="Engines">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="Engine" />
</xs:sequence>
<xs:attribute name="Count" use="required" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="Engine">
<xs:complexType>
<xs:sequence>
<xs:element name="Model" type="Model"/>
<xs:element ref="SerialNumber" />
</xs:sequence>
</xs:complexType>
</element>
<xs:simpleType name="trimValueType">
<xs:restriction base="xs:string">
<xs:minLength value="1"></xs:minLength>
<xs:whiteSpace value="collapse"></xs:whiteSpace>
</xs:restriction>
</xs:simpleType>
<xs:complexTyp‌​e name="Model">
<xs:simpleContent>
<xs:extension base="trimValueType">
<xs:attribute name="ATTRIBUTE" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<Engines count = 1> <Engine> <Model ATTRIBUTE = "r\w"> </Model> <SerialNumber ATTRIBUTE = "r/w">1234567</SerialNumber> <Engine> <Engines>
You have to first create a simple type that restricts xsd:string to specify your text constraints. Then you need to define a complex type, with a simple content, which extends the simple type you just created using the attributes you want. I threw in a whitespace constraint, just to match your title, even though you're not specifically mention it in your problem statement.
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:simpleType name="one">
<xsd:restriction base="xsd:string">
<xsd:whiteSpace value="collapse"/>
<xsd:minLength value="1"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="two">
<xsd:simpleContent>
<xsd:extension base="one">
<xsd:attribute name="one"/>
<xsd:attribute name="two"/>
<xsd:attribute name="etc"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:element name="root" type="two"/>
</xsd:schema>
Sample XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" one="anySimpleType" two="anySimpleType" etc="anySimpleType" xmlns="http://tempuri.org/XMLSchema.xsd">root1</root>

Categories