CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
xml_schema_validator.h
1
2
3#pragma once
4
5#include <xml/xml_char_type.h>
6#include <xml/schema/xml_schema_validation_flags.h>
7#include <xml/schema/validation_event_handler.h>
8#include <system/multicast_delegate.h>
9#include <system/exceptions.h>
10#include <system/enum_helpers.h>
11#include <system/array.h>
12#include <cstdint>
13
14
16namespace System
17{
18namespace Collections
19{
20namespace Generic
21{
22template <typename, typename> class Dictionary;
23template <typename> class List;
24} // namespace Generic
25} // namespace Collections
26namespace Text
27{
28class StringBuilder;
29} // namespace Text
30class Uri;
31namespace Xml
32{
33class DocumentSchemaValidator;
34class HWStack;
35class IDtdInfo;
36class IXmlLineInfo;
37class IXmlNamespaceResolver;
38namespace Schema
39{
40class BaseValidator;
41class DtdValidator;
42class IdRefNode;
43class SchemaAttDef;
44class SchemaDeclBase;
45class SchemaElementDecl;
46class SchemaInfo;
47class ValidationState;
48enum class ValidatorState;
49class XdrValidator;
50class XmlSchema;
51class XmlSchemaAttribute;
53enum class XmlSchemaContentType;
54class XmlSchemaDatatype;
55class XmlSchemaElement;
56class Details_XmlSchemaException; using XmlSchemaException = System::ExceptionWrapper<Details_XmlSchemaException>;
57class XmlSchemaInfo;
58class XmlSchemaObject;
59class XmlSchemaParticle;
60class XmlSchemaSet;
61class XmlSchemaSimpleType;
63enum class XmlSeverityType;
64class XsdValidator;
65} // namespace Schema
66class XmlNameTable;
67class XmlQualifiedName;
68class XmlResolver;
69enum class XmlTokenizedType;
70class XsdValidatingReader;
71} // namespace Xml
72} // namespace System
74
75namespace System {
76
77namespace Xml {
78
79namespace Schema {
80
85using XmlValueGetter = System::MulticastDelegate<SharedPtr<Object>()>;
86
92class ASPOSECPP_SHARED_CLASS XmlSchemaValidator final : public System::Object
93{
96
97 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
98 ASPOSECPP_SHARED_RTTI_INFO_DECL();
99
100public:
101
104
105private:
107 friend class System::Xml::XsdValidatingReader;
108 friend class System::Xml::DocumentSchemaValidator;
109 friend class BaseValidator;
110 friend class DtdValidator;
111 friend class XdrValidator;
112 friend class XsdValidator;
114
115public:
116
119
123 ASPOSECPP_SHARED_API void set_XmlResolver(const SharedPtr<System::Xml::XmlResolver>& value);
129 ASPOSECPP_SHARED_API void set_LineInfoProvider(const SharedPtr<IXmlLineInfo>& value);
132 ASPOSECPP_SHARED_API SharedPtr<Uri> get_SourceUri();
135 ASPOSECPP_SHARED_API void set_SourceUri(const SharedPtr<Uri>& value);
141 ASPOSECPP_SHARED_API void set_ValidationEventSender(const SharedPtr<Object>& value);
142
150 ASPOSECPP_SHARED_API XmlSchemaValidator(const SharedPtr<XmlNameTable>& nameTable, const SharedPtr<XmlSchemaSet>& schemas, const SharedPtr<IXmlNamespaceResolver>& namespaceResolver, XmlSchemaValidationFlags validationFlags);
151
158 ASPOSECPP_SHARED_API void AddSchema(const SharedPtr<XmlSchema>& schema);
162 ASPOSECPP_SHARED_API void Initialize();
171 ASPOSECPP_SHARED_API void Initialize(const SharedPtr<XmlSchemaObject>& partialValidationType);
180 ASPOSECPP_SHARED_API void ValidateElement(const String& localName, const String& namespaceUri, const SharedPtr<XmlSchemaInfo>& schemaInfo);
195 ASPOSECPP_SHARED_API void ValidateElement(const String& localName, const String& namespaceUri, const SharedPtr<XmlSchemaInfo>& schemaInfo, const String& xsiType, const String& xsiNil, const String& xsiSchemaLocation, const String& xsiNoNamespaceSchemaLocation);
207 ASPOSECPP_SHARED_API SharedPtr<Object> ValidateAttribute(const String& localName, const String& namespaceUri, const String& attributeValue, const SharedPtr<XmlSchemaInfo>& schemaInfo);
220 ASPOSECPP_SHARED_API SharedPtr<Object> ValidateAttribute(const String& localName, const String& namespaceUri, XmlValueGetter attributeValue, const SharedPtr<XmlSchemaInfo>& schemaInfo);
226 ASPOSECPP_SHARED_API void GetUnspecifiedDefaultAttributes(const SharedPtr<Collections::Generic::List<SharedPtr<Object>>>& defaultAttributes);
236 ASPOSECPP_SHARED_API void ValidateEndOfAttributes(const SharedPtr<XmlSchemaInfo>& schemaInfo);
244 ASPOSECPP_SHARED_API void ValidateText(const String& elementValue);
253 ASPOSECPP_SHARED_API void ValidateText(XmlValueGetter elementValue);
260 ASPOSECPP_SHARED_API void ValidateWhitespace(const String& elementValue);
268 ASPOSECPP_SHARED_API void ValidateWhitespace(XmlValueGetter elementValue);
277 ASPOSECPP_SHARED_API SharedPtr<Object> ValidateEndElement(const SharedPtr<XmlSchemaInfo>& schemaInfo);
288 ASPOSECPP_SHARED_API SharedPtr<Object> ValidateEndElement(const SharedPtr<XmlSchemaInfo>& schemaInfo, const SharedPtr<Object>& typedValue);
296 ASPOSECPP_SHARED_API void SkipToEndElement(const SharedPtr<XmlSchemaInfo>& schemaInfo);
299 ASPOSECPP_SHARED_API void EndValidation();
306
307protected:
308
310 static ArrayPtr<std::vector<bool>> ValidStates;
311
312 SharedPtr<XmlSchemaSet> get_SchemaSet();
313 XmlSchemaValidationFlags get_ValidationFlags();
314 XmlSchemaContentType get_CurrentContentType();
315 XmlSchemaContentProcessing get_CurrentProcessContents();
316 bool get_ProcessIdentityConstraints();
317 bool get_ReportValidationWarnings();
318 bool get_ProcessSchemaHints();
319
320 void GetUnspecifiedDefaultAttributes(const SharedPtr<Collections::Generic::List<SharedPtr<Object>>>& defaultAttributes, bool createNodeData);
321 void SetDtdSchemaInfo(const SharedPtr<IDtdInfo>& dtdSchemaInfo);
322 String GetConcatenatedValue();
323 SharedPtr<Object> CheckMixedValueConstraint(const String& elementValue);
324 void RecompileSchemaSet();
325 String GetDefaultAttributePrefix(const String& attributeNS);
326 static void ElementValidationError(const SharedPtr<XmlQualifiedName>& name, const SharedPtr<ValidationState>& context, System::Xml::Schema::ValidationEventHandler eventHandler, const SharedPtr<Object>& sender, const String& sourceUri, int32_t lineNo, int32_t linePos, const SharedPtr<XmlSchemaSet>& schemaSet);
327 static void CompleteValidationError(const SharedPtr<ValidationState>& context, System::Xml::Schema::ValidationEventHandler eventHandler, const SharedPtr<Object>& sender, const String& sourceUri, int32_t lineNo, int32_t linePos, const SharedPtr<XmlSchemaSet>& schemaSet);
328 static String PrintExpectedElements(const SharedPtr<Collections::Generic::List<SharedPtr<XmlSchemaParticle>>>& expected);
329 static String PrintExpectedElements(const SharedPtr<Collections::Generic::List<String>>& expected);
330 static String QNameString(const String& localName, const String& ns);
331 static String BuildElementName(const SharedPtr<XmlQualifiedName>& qname);
332 static String BuildElementName(const String& localName, const String& ns);
333 static void SendValidationEvent(System::Xml::Schema::ValidationEventHandler eventHandler, const SharedPtr<Object>& sender, XmlSchemaValidationException e, XmlSeverityType severity);
335
336 virtual ASPOSECPP_SHARED_API ~XmlSchemaValidator();
337
339 #ifdef ASPOSE_GET_SHARED_MEMBERS
340 ASPOSECPP_SHARED_API void GetSharedMembers(System::Object::shared_members_type& result) const override;
341 #endif
343
344private:
345
346 SharedPtr<XmlSchemaSet> _schemaSet;
347 XmlSchemaValidationFlags _validationFlags;
348 int32_t _startIDConstraint;
349 static const int32_t STACK_INCREMENT;
350 bool _isRoot;
351 bool _rootHasSchema;
352 bool _attrValid;
353 bool _checkEntity;
354 SharedPtr<SchemaInfo> _compiledSchemaInfo;
355 SharedPtr<IDtdInfo> _dtdSchemaInfo;
357 SharedPtr<HWStack> _validationStack;
359 ValidatorState _currentState;
363 SharedPtr<IdRefNode> _idRefListHead;
364 SharedPtr<XmlQualifiedName> _contextQName;
365 String _nsXs;
366 String _nsXsi;
367 String _nsXmlNs;
368 String _nsXml;
369 SharedPtr<XmlSchemaObject> _partialValidationType;
371 WeakPtr<Object> _validationEventSender;
372 SharedPtr<XmlNameTable> _nameTable;
373 SharedPtr<IXmlLineInfo> _positionInfo;
374 SharedPtr<IXmlLineInfo> _dummyPositionInfo;
376 SharedPtr<Uri> _sourceUri;
377 String _sourceUriString;
379 XmlSchemaContentProcessing _processContents;
380 static SharedPtr<XmlSchemaAttribute> s_xsiTypeSO;
381 static SharedPtr<XmlSchemaAttribute> s_xsiNilSO;
382 static SharedPtr<XmlSchemaAttribute> s_xsiSLSO;
383 static SharedPtr<XmlSchemaAttribute> s_xsiNoNsSLSO;
384 String _xsiTypeString;
385 String _xsiNilString;
386 String _xsiSchemaLocationString;
387 String _xsiNoNamespaceSchemaLocationString;
388 static SharedPtr<XmlSchemaDatatype> s_dtQName;
389 static SharedPtr<XmlSchemaDatatype> s_dtCDATA;
390 static SharedPtr<XmlSchemaDatatype> s_dtStringArray;
391 static const String Quote;
392 static ArrayPtr<SharedPtr<XmlSchemaParticle>> s_emptyParticleArray;
393 static ArrayPtr<SharedPtr<XmlSchemaAttribute>> s_emptyAttributeArray;
394 XmlCharType _xmlCharType;
395 static ArrayPtr<String> s_methodNames;
396
397 bool get_StrictlyAssessed();
398 bool get_HasSchema();
399 bool get_HasIdentityConstraints();
401
402 void Init();
403 void Reset();
404 SharedPtr<Object> ValidateAttribute(String localName, String namespaceUri, XmlValueGetter attributeValueGetter, const String& attributeStringValue, const SharedPtr<XmlSchemaInfo>& schemaInfo);
405 void ValidateText(const String& elementStringValue, XmlValueGetter elementValueGetter);
406 void ValidateWhitespace(const String& elementStringValue, XmlValueGetter elementValueGetter);
407 SharedPtr<Object> InternalValidateEndElement(const SharedPtr<XmlSchemaInfo>& schemaInfo, SharedPtr<Object> typedValue);
408 void ProcessSchemaLocations(const String& xsiSchemaLocation, const String& xsiNoNamespaceSchemaLocation);
409 SharedPtr<Object> ValidateElementContext(const SharedPtr<XmlQualifiedName>& elementName, bool& invalidElementInContext);
410 SharedPtr<XmlSchemaElement> GetSubstitutionGroupHead(const SharedPtr<XmlQualifiedName>& member);
411 SharedPtr<Object> ValidateAtomicValue(const String& stringValue, SharedPtr<XmlSchemaSimpleType>& memberType);
412 SharedPtr<Object> ValidateAtomicValue(const SharedPtr<Object>& parsedValue, SharedPtr<XmlSchemaSimpleType>& memberType);
413 String GetTypeName(const SharedPtr<SchemaDeclBase>& decl);
414 void SaveTextValue(const SharedPtr<Object>& value);
415 void Push(const SharedPtr<XmlQualifiedName>& elementName);
416 void Pop();
417 void AddXsiAttributes(const SharedPtr<Collections::Generic::List<SharedPtr<XmlSchemaAttribute>>>& attList);
418 SharedPtr<SchemaElementDecl> FastGetElementDecl(const SharedPtr<XmlQualifiedName>& elementName, const SharedPtr<Object>& particle);
419 SharedPtr<SchemaElementDecl> CheckXsiTypeAndNil(SharedPtr<SchemaElementDecl> elementDecl, const String& xsiType, const String& xsiNil, bool& declFound);
420 void ThrowDeclNotFoundWarningOrError(bool declFound);
421 void CheckElementProperties();
422 void ValidateStartElementIdentityConstraints();
423 SharedPtr<SchemaAttDef> CheckIsXmlAttribute(const SharedPtr<XmlQualifiedName>& attQName);
424 void AddXmlNamespaceSchema();
425 void LoadSchema(const String& uri, const String& url);
426 void ProcessTokenizedType(XmlTokenizedType ttype, const String& name, bool attrValue);
427 SharedPtr<Object> CheckAttributeValue(const SharedPtr<Object>& value, const SharedPtr<SchemaAttDef>& attdef);
428 SharedPtr<Object> CheckElementValue(const String& stringValue);
429 void CheckTokenizedTypes(const SharedPtr<XmlSchemaDatatype>& dtype, const SharedPtr<Object>& typedValue, bool attrValue);
430 SharedPtr<Object> FindId(const String& name);
431 void CheckForwardRefs();
432 void CheckStateTransition(ValidatorState toState, const String& methodName);
433 void ClearPSVI();
434 void CheckRequiredAttributes(const SharedPtr<SchemaElementDecl>& currentElementDecl);
435 SharedPtr<XmlSchemaElement> GetSchemaElement();
436 void AddIdentityConstraints();
437 void ElementIdentityConstraints();
438 void AttributeIdentityConstraints(const String& name, const String& ns, const SharedPtr<Object>& obj, const String& sobj, const SharedPtr<XmlSchemaDatatype>& datatype);
439 void EndElementIdentityConstraints(const SharedPtr<Object>& typedValue, const String& stringValue, const SharedPtr<XmlSchemaDatatype>& datatype);
440 static void BuildXsiAttributes();
441 static void PrintNamesWithNS(const SharedPtr<Collections::Generic::List<SharedPtr<XmlQualifiedName>>>& expected, const SharedPtr<Text::StringBuilder>& builder);
442 static void EnumerateAny(const SharedPtr<Text::StringBuilder>& builder, const String& namespaces);
443 void ProcessEntity(const String& name);
444 void SendValidationEvent(const String& code);
445 void SendValidationEvent(const String& code, const ArrayPtr<String>& args);
446 void SendValidationEvent(const String& code, const String& arg);
447 void SendValidationEvent(const String& code, const String& arg1, const String& arg2);
448 void SendValidationEvent(const String& code, const ArrayPtr<String>& args, Exception innerException, XmlSeverityType severity);
449 void SendValidationEvent(const String& code, const ArrayPtr<String>& args, Exception innerException);
450 void SendValidationEvent(XmlSchemaValidationException e);
451 void SendValidationEvent(XmlSchemaException e);
452 void SendValidationEvent(const String& code, const String& msg, XmlSeverityType severity);
453 void SendValidationEvent(XmlSchemaValidationException e, XmlSeverityType severity);
454
455 static struct __StaticConstructor__ { __StaticConstructor__(); } s_constructor__;
456
457};
458
459} // namespace Schema
460} // namespace Xml
461} // namespace System
462
463
List forward declaration.
Definition: list.h:127
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
Subclass of System::SmartPtr which sets itself to weak mode at construction. Please note that this cl...
Definition: weak_ptr.h:18
Represents an XML Schema Definition Language (XSD) Schema validation engine. The XmlSchemaValidator c...
Definition: xml_schema_validator.h:93
void ValidateText(const String &elementValue)
Validates whether the text string specified is allowed in the current element context,...
SharedPtr< IXmlLineInfo > get_LineInfoProvider()
Returns the line number information for the XML node being validated.
SharedPtr< Object > ValidateAttribute(const String &localName, const String &namespaceUri, const String &attributeValue, const SharedPtr< XmlSchemaInfo > &schemaInfo)
Validates the attribute name, namespace URI, and value in the current element context.
SharedPtr< Object > get_ValidationEventSender()
Returns the object sent as the sender object of a validation event.
XmlSchemaValidator(const SharedPtr< XmlNameTable > &nameTable, const SharedPtr< XmlSchemaSet > &schemas, const SharedPtr< IXmlNamespaceResolver > &namespaceResolver, XmlSchemaValidationFlags validationFlags)
Initializes a new instance of the XmlSchemaValidator class.
void set_SourceUri(const SharedPtr< Uri > &value)
Sets the source URI for the XML node being validated.
SharedPtr< Object > ValidateEndElement(const SharedPtr< XmlSchemaInfo > &schemaInfo)
Verifies if the text content of the element is valid according to its data type for elements with sim...
void ValidateWhitespace(const String &elementValue)
Validates whether the white space in the string specified is allowed in the current element context,...
void ValidateElement(const String &localName, const String &namespaceUri, const SharedPtr< XmlSchemaInfo > &schemaInfo, const String &xsiType, const String &xsiNil, const String &xsiSchemaLocation, const String &xsiNoNamespaceSchemaLocation)
Validates the element in the current context with the xsi:Type, xsi:Nil, xsi:SchemaLocation,...
void AddSchema(const SharedPtr< XmlSchema > &schema)
Adds an XML Schema Definition Language (XSD) schema to the set of schemas used for validation.
void ValidateText(XmlValueGetter elementValue)
Validates whether the text returned by the XmlValueGetter object specified is allowed in the current ...
void EndValidation()
Ends validation and checks identity constraints for the entire XML document.
void ValidateElement(const String &localName, const String &namespaceUri, const SharedPtr< XmlSchemaInfo > &schemaInfo)
Validates the element in the current context.
void set_LineInfoProvider(const SharedPtr< IXmlLineInfo > &value)
Sets the line number information for the XML node being validated.
SharedPtr< Uri > get_SourceUri()
Returns the source URI for the XML node being validated.
void set_XmlResolver(const SharedPtr< System::Xml::XmlResolver > &value)
Sets the XmlResolver object used to resolve xs:import and xs:include elements as well as xsi:schemaLo...
void ValidateEndOfAttributes(const SharedPtr< XmlSchemaInfo > &schemaInfo)
Verifies whether all the required attributes in the element context are present and prepares the XmlS...
void GetUnspecifiedDefaultAttributes(const SharedPtr< Collections::Generic::List< SharedPtr< Object > > > &defaultAttributes)
Validates identity constraints on the default attributes and populates the List specified with XmlSch...
void Initialize()
Initializes the state of the XmlSchemaValidator object.
void set_ValidationEventSender(const SharedPtr< Object > &value)
Sets the object sent as the sender object of a validation event.
System::Xml::Schema::ValidationEventHandler ValidationEventHandler
The ValidationEventHandler that receives schema validation warnings and errors encountered during sch...
Definition: xml_schema_validator.h:118
ArrayPtr< SharedPtr< XmlSchemaAttribute > > GetExpectedAttributes()
Returns the expected attributes for the current element context.
void SkipToEndElement(const SharedPtr< XmlSchemaInfo > &schemaInfo)
Skips validation of the current element content and prepares the XmlSchemaValidator object to validat...
SharedPtr< Object > ValidateAttribute(const String &localName, const String &namespaceUri, XmlValueGetter attributeValue, const SharedPtr< XmlSchemaInfo > &schemaInfo)
Validates the attribute name, namespace URI, and value in the current element context.
void Initialize(const SharedPtr< XmlSchemaObject > &partialValidationType)
Initializes the state of the XmlSchemaValidator object using the XmlSchemaObject specified for partia...
void ValidateWhitespace(XmlValueGetter elementValue)
Validates whether the white space returned by the XmlValueGetter object specified is allowed in the c...
ArrayPtr< SharedPtr< XmlSchemaParticle > > GetExpectedParticles()
Returns the expected particles in the current element context.
SharedPtr< Object > ValidateEndElement(const SharedPtr< XmlSchemaInfo > &schemaInfo, const SharedPtr< Object > &typedValue)
Verifies if the text content of the element specified is valid according to its data type.
For internal purposes. Do not use this class directly.
Definition: xml_char_type.h:61
class ASPOSECPP_SHARED_CLASS List
Definition: ienumerable.h:18
@ Text
Defines color adjustment information for text.
System::ExceptionWrapper< Details_XmlSchemaValidationException > XmlSchemaValidationException
Definition: xml_schema_validation_exception.h:36
System::ExceptionWrapper< Details_XmlSchemaException > XmlSchemaException
Definition: xml_schema_exception.h:76
XmlSchemaContentType
Enumerations for the content model of the complex type. This represents the content in the post-schem...
Definition: xml_schema_content_type.h:18
System::MulticastDelegate< void(SharedPtr< Object >, SharedPtr< ValidationEventArgs >)> ValidationEventHandler
Represents the callback method that will handle XML schema validation events and the ValidationEventA...
Definition: validation_event_handler.h:33
System::MulticastDelegate< SharedPtr< Object >()> XmlValueGetter
A callback used by the XmlSchemaValidator class to pass attribute, text,and white space values as a r...
Definition: xml_schema_validator.h:85
XmlSeverityType
Represents the severity of the validation event.
Definition: xml_severity_type.h:17
XmlSchemaContentProcessing
Provides information about the validation mode of any and anyAttribute element replacements.
Definition: xml_schema_content_processing.h:17
XmlSchemaValidationFlags
Specifies schema validation options used by the XmlSchemaValidator and XmlReader classes.
Definition: xml_schema_validation_flags.h:18
@ Schema
Validate according to XML Schema definition language (XSD) schemas, including inline XML Schemas....
@ Xml
Serialize according to the XML 1.0 rules.
XmlTokenizedType
Represents the XML type for the string. This allows the string to be read as a particular XML type,...
Definition: xml_tokenized_type.h:16
Definition: db_command.h:9