Reputation: 145
I have an XML document as below:
<?xml version="1.0" encoding="UTF-8"?>
<cbe:CommonBaseEvents xmlns:cbe="http://www.ibm.com/AC/commonbaseevent1_1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<cbe:CommonBaseEvent>
<sourceComponentId component="25541"
componentIdType="Application" location="abcxxxxx"
locationType="Hostname" subComponent="ia" />
<situationInformation extensionName="FeedNotification"
creationTime="2008-02-08T12:00:00">
<extendedDataElements name="FeedNotification"
type="string">
<children name="fileType" type="string">
<values>ACBAL</values>
</children>
<children name="file" type="string">
<values>acountandbalances/input/finalT24_ACBAL_MY0010001_200902115941323.csv</values>
</children>
<children name="archiveDirectory" type="string">
<values>accountandbalances/input/archive</values>
</children>
</extendedDataElements>
<situationType category="CREATE" successDisposition="SUCCESSFUL"
situationQualifier="FileTransfer" reasoningScope="INFO" />
</situationInformation>
</cbe:CommonBaseEvent>
</cbe:CommonBaseEvents>
And i have created a schema for this XML as below:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cbe="http://www.ibm.com/AC/commonbaseevent1_1">
<xs:include schemaLocation="../../00.GEN.Generic/INTF/COMMON_RULES.xsd" />
<xs:complexType name="sourceComponentIdType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="component" type="xs:string"/>
<xs:attribute name="componentIdType" type="xs:string"/>
<xs:attribute name="location" type="xs:string"/>
<xs:attribute name="locationType" type="xs:string"/>
<xs:attribute name="subComponent" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name = "cbe:CommonBaseEvents">
<xs:complexType>
<xs:sequence>
<xs:element name = "cbe:CommonBaseEvent">
<xs:complexType>
<xs:sequence>
<xs:element name="sourceComponentId" type="sourceComponentIdType" />
<xs:element name="situationInformation">
<xs:complexType>
<xs:sequence>
<xs:element name="extendedDataElements">
<xs:complexType>
<xs:sequence>
<xs:element name="children" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="values" type="xs:string" />
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="type" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="type" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="extensionName" type="xs:string"/>
<xs:attribute name="creationTime" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
However, while validating XML vs Schema, i get an error that says:
Error - Line 18, 44: org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 44; s4s-att-invalid-value: Invalid attribute value for 'name' in element 'element'. Recorded reason: cvc-datatype-valid.1.2.1: 'cbe:CommonBaseEvents' is not a valid value for 'NCName'.
Error - Line 18, 44: org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 44; s4s-att-must-appear: Attribute 'name' must appear in element 'element'.
Error - Line 21, 46: org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 46; s4s-att-invalid-value: Invalid attribute value for 'name' in element 'element'. Recorded reason: cvc-datatype-valid.1.2.1: 'cbe:CommonBaseEvent' is not a valid value for 'NCName'.
Error - Line 21, 46: org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 46; src-element.2.1: : One of 'ref' or 'name' must be present in a local element declaration.
Please help me understand what am i doing wrong here, i am sure its something to do with the schema not understanding where "cbe" prefix is coming from.
Upvotes: 0
Views: 10927
Reputation: 21638
Welcome to SO... Your sample and XSD are misleading, if only because there's no attribute name showing a cbe:CommonBaseEvent value.
That being said, the error really tells you what the problem is. You need to look it up, and learn more about what NCName is.
Here is a repro:
An XSD:
<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:NCName"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
An 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" name="cbe:CommonBaseEvents"/>
The error:
Error occurred while loading [], line 3 position 61 The 'name' attribute is invalid - The value 'cbe:CommonBaseEvents' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:NCName' - The ':' character, hexadecimal value 0x3A, cannot be included in a name.
Error while loading [], line 3 position 90 cvc-datatype-valid.1.2.1: 'cbe:CommonBaseEvents' is not a valid value for 'NCName'.
Here it was the cvc-datatype-valid.1.2.1 explained better (basically, : is invalid).
NCName is described here.
Upvotes: 4