You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Swaminathan A <Sw...@siemens.com> on 2004/03/18 14:43:10 UTC

[AA] Validation error when parsing a XML having a list using SAX Parser in Xerces 2.2.0

Hi all,

Used Xerces Version: 2.2.0

During the validation of a XML file using SAX parser, when xs:list is used,
validation fails.
Is there any way to get the same requirement of having a list satisfied ?


Error Message given by the SAX Parser is 
Message: Datatype error: Type:InvalidDatatypeValueException, Message:Value
'SAVE_PRIVATE_TASKS ALIGN_ALARM_STATUS' is not in enumeration .

Schema is 
	<xs:simpleType name="USERPRIVILEGESLIST">
		<xs:list itemType="NONEMPTYSTRING"/>
	</xs:simpleType>

	<xs:simpleType name="USERPRIVILEGES">
		<xs:restriction base="USERPRIVILEGESLIST">
			<xs:maxLength value="7"/>
			<xs:minLength value="1"/>
			<xs:enumeration value="ALIGN_ALARM_STATUS"/>
			<xs:enumeration value="CLEAR_ALARMS"/>
			<xs:enumeration
value="CLEAR_AUTOMATICALLY_CLEARABLE_ALARMS"/>
			<xs:enumeration value="CONFIRM_ALARMS"/>
			<xs:enumeration value="CREATE_WORK_ORDER"/>
			<xs:enumeration value="VIEW_SECURITY_ALARMS"/>
			<xs:enumeration value="SAVE_PRIVATE_TASKS"/>
		</xs:restriction>
	</xs:simpleType>

	<xs:complexType name="CreateAdminDBUser">

		<!-- Optional Parameters -->
		<xs:attribute name="ContinueOnError" 	type="xs:boolean"/>
		<xs:attribute name="SuccessLogString" 	type="xs:string"/>
		<xs:attribute name="ErrorLogString" 	type="xs:string"/>

		<!-- Mandatory Parameters -->
		<xs:attribute name="UserName"
type="NONEMPTYSTRING" 	use="required"/>
		<xs:attribute name="UserPwd"
type="NONEMPTYSTRING"/>
		<xs:attribute name="ApplicationList" 	type="xs:string"
use="required"/>
		<xs:attribute name="UGList" 		type="xs:string"
use="required"/>
		<!--xs:attribute name="Privilege"
type="USERPRIVILEGES" 	use="required"/-->
		<xs:attribute name="Privilege"
type="NONEMPTYSTRING" 	use="required"/>
	</xs:complexType>

Usage in XML file 
<CreateAdminDBUser UserName="%%FIRST_ADMIN_USER%%"
UserPwd="%%FIRST_ADMIN_USER_PWD%%" ApplicationList="" UGList=""
Privilege="SAVE_PRIVATE_TASKS ALIGN_ALARM_STATUS"/>

Code used for parsing is

		strTmpXMLFilePath is the xml file name.
		m_strSchemaFileName is the Schema file name.

		SAX2XMLReader* m_pXMLParser;	

		//Set the External Schema File Name.
		try
		{
			XMLCh* propertyValue =
(LPTSTR)(LPCTSTR)m_strSchemaFileName;
	
m_pXMLParser->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLoc
ation,propertyValue);
		}
		catch(const SAXException& toCatch)
		{			
			return ERR_FAILURE;
		}
		catch (...)
		{	
			strTraceMessage.Format(_T("ERROR: Unexpected
exception during setting the external \
				schema file name :
%s"),m_strSchemaFileName);
			cout << strTraceMessage;
			return ERR_FAILURE;
		}
		
		//Parse the XML file.
		try
		{
			m_pXMLParser->parse(strTmpXMLFilePath);
		}		
		catch (const XMLException& toCatch)
		{
			strTraceMessage.Format(_T("ERROR: Error during
parsing the given file ! Message: %s"),
				toCatch.getMessage());
			cout << strTraceMessage;
			return ERR_FAILURE;
		}		
		catch (...)
		{	
			strTraceMessage.Format(_T("ERROR: Unexpected
exception during parsing: %s"),strTmpXMLFilePath);
			cout << strTraceMessage;
			return ERR_FAILURE;
		}				


Best Regards,
Swaminathan

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: [AA] Validation error when parsing a XML having a list using SAX Parser in Xerces 2.2.0

Posted by Gareth Reakes <pa...@parthenoncomputing.com>.
Hi,

> 	<xs:simpleType name="USERPRIVILEGES">
> 		<xs:restriction base="USERPRIVILEGESLIST">
> 			<xs:maxLength value="7"/>
> 			<xs:minLength value="1"/>

You have not given the full schema but this looks a little suspicious to
me. Is maxLength referring to the length of the strings in
the enumerations? If so then both of your examples are longer than 7.
Check this out by putting a value that is actually less than 7 in there.


Gareth

--
Gareth Reakes, Managing Director            +44-1865-811184
Parthenon Computing                http://www.parthcomp.com

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org