0

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.

Plainsage
  • 116
  • 1
  • 2
  • 11
  • The error means that when you're defining an element in XSD, you should not use a namespace prefix in `xs:element/@name`. If this doesn't help sufficiently, for a more comprehensive answer, please add the included `./../00.GEN.Generic/INTF/COMMON_RULES.xsd` XSD to your question. Thanks. – kjhughes Feb 12 '15 at 13:28
  • Thanks for the reply, i am still not clear on what i should change to get a correct schema. However, please ignore the {./../00.GEN.Generic/INTF/COMMON_RULES.xsd} part as that is different and it has nothing to do with this error. – Plainsage Feb 12 '15 at 13:34
  • 1
    If you want us to ignore an included XSD as irrelevant, then please prune your example down to exclude it, else you've not provided a [**Minimal, Complete, and Verifiable Example (MCVE)**](http://stackoverflow.com/help/mcve). Note that if you truly want to mix namespaced and non-namespaced elements in your XML, expect to define them in separate XSDs where one uses `xsd:import` to import the other. Try to follow the example given in [XSD with elements from other namespace](http://stackoverflow.com/q/6413145/290085) and then update your question if you still have trouble. Thanks. – kjhughes Feb 12 '15 at 14:07

1 Answers1

4

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.

Petru Gardea
  • 21,373
  • 2
  • 50
  • 62
  • also see this post for information on `NCName` http://stackoverflow.com/questions/1631396/what-is-an-xsncname-type-and-when-should-it-be-used – Kirby Aug 02 '16 at 19:31