Last active
March 9, 2023 11:03
-
-
Save adojos/9b1bc46f6832002e7f26da7379f59aa2 to your computer and use it in GitHub Desktop.
VBS: Load XSD Schema from XSD File #vbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Function LoadSchemaCache (objSchemaColl, objXSDFile) | |
Dim strNsURI | |
'Get targetNamespace property from XSD | |
strNsURI = GetNamespaceURI (objXSDFile) | |
'Load XSD from the Path | |
objSchemaColl.Add strNsURI, objXSDFile | |
Set LoadSchemaCache = objSchemaColl | |
End Function | |
Public Function GetNamespaceURI (ObjXML) | |
Dim strNsURI | |
strNsURI = ObjXML.documentElement.getAttribute("targetNamespace") | |
If strNsURI <> "" Then | |
GetNamespaceURI = strNsURI | |
Else | |
strNsURI = ObjXML.namespaceURI | |
GetNamespaceURI = strNsURI | |
End If | |
End Function | |
Function GetSchemaCacheForXSDs() | |
Set ObjSchemaCache = CreateObject("MSXML2.XMLSchemaCache.6.0") | |
'Indicates whether the schema will be compiled and validated when it is loaded into the schema cache | |
ObjSchemaCache.validateOnload = False ' This method applies to only [Schema Cache] not (XSD or XML) | |
Set objXSDFile = LoadXML(strInput) | |
Set ObjSchemaCache = LoadSchemaCache(ObjSchemaCache, objXSDFile) | |
Set GetSchemaCacheForXSDs = ObjSchemaCache | |
End Function | |
Public Function LoadXML(strXmlPath) | |
Dim ObjParseErr, ObjXML | |
Dim IsWait | |
Set ObjXML = CreateObject ("MSXML2.DOMDocument.6.0") | |
' WScript.Echo("Microsoft XML Core Services (MSXML) 6.0 is not installed.\n" | |
' +"Download and install MSXML 6.0 from http://msdn.microsoft.com/xml\n" | |
' +"before continuing."); | |
With ObjXML | |
'Set First Level DOM Properties | |
.async = False | |
.validateOnParse = False | |
.resolveExternals = False | |
End With | |
ObjXML.Load (strXmlPath) | |
Set ObjError = ObjXML.parseError | |
With ObjError | |
If .errorCode <> 0 Then | |
msgbox "XML Document could not be loaded!!!" & vbCrLf &_ | |
"ErrorCode: " & .errorCode & vbCrLf &_ | |
"Line: " & .line & vbCrLf &_ | |
"Reason: " & .reason & vbCrLf &_ | |
"Path: " & .URL | |
Else | |
msgbox "XML Loaded Successfully!" | |
Set LoadXML = ObjXML | |
End If | |
End With | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment