MSXML 6.0 vs. System.Xml

http://blogs.msdn.com/stan_kitsis/archive/2005/09/20/472185.aspx

 

Feature MSXML 6 system.xml

Using XML attributes without explicit schema declaration not supported supported
element of type xs:ID supported* not supported
Conflicting values of facets minInclusive, maxInclusive in base and derived types not allowed* allowed
maxOccurs=0 with no minOccurs error* no error
Multiple redefines of the same schema document error warning (only first redefine is processed)
parsing of targetNamespace attribute as anyURI supported* not supported
Regex support for Unicode Character blocks Unicode 3.1 Unicode 4.0.1
Regex patterns involving combinating a negative group with another using ‘|’ not supported supported*
XSD Errata for Regex E2-52 not supported supported*
Regex character class subtraction not supported supported*
Matching newlines/linebreaks from a xsd:pattern facet not supported supported*
minOccurs/maxOccurs value limits upto 2^32 CLR decimal
limit of totalDigits facet values upto 2^32 CLR decimal
datatypes used to store length, minLength, maxLength facet values upto 2^32 CLR decimal
a prohibited attribute in a complex type no error, attribute stripped* warning, attribute stripped*
unreferenced groups in the schema always compiled compiled on reference
default element values availability not supported supported*
expose post schema validation infoset not supported supported*
ENTITY in DTD resolvable by attribute/elements of type xs:ENTITY DOM=Yes, SAX=no Yes
adding a default qualified attribute to an element in a document that has attribute’s namespace as default DOM: apply qualified default attribute with namespace value as the prefix. SAX=does not generate prefix for default qualified attributes error
identity constraints (key/unique) evaluation for skip/lax blocks node is null not able to find node
element with mixed content, and a fixed schema value, containing child elements instance accepted instance not accepted*
whitespace facet on anySimpleType preserve* collapsed
XSD Errata on xs:base64Binary parsing supported* not supported
xs:dateTime: number of year digits supported 10 4
xs:dateTIme: number of fraction digits supported in seconds 9 7
xs:dateTime: Range of hours in time zone “-14:00 to +14:00” * 99:00 to -99:00
xs:dateTime: negative years supported* not supported
“z” (as opposed to “Z”) in xs:dateTime to represent UTC time not allowed* allowed
xs:time: range of hour value 00:00:00 to 24:00:00* 00:00:00 to 23:59:59
xs:gMonth: XSD Errata revised the lexical representation of gMonth only –MM is allowed* both –MM and –MM– are allowed
maximum digits allowed for the xs:decimal data type 128 29
xs:duration: duration with second part specified, but has no digits error no error, infer a 0 for the second part
msval.vbs

Option Explicit

' Initialize global objects and variables.
Dim fso, f, file, folder, filepath, dir, coll
Dim fspec, strFileName, shortName, strResult
Dim LineOfEquals, strFile, strFiles, strFileExt
Dim Files, StartingFolder, WshShell, strDesktop
Dim S, SubFolders, SubFolder, procFilesCount
Dim xmlDoc, state
Dim sLogPath

'Set global constants and variables.
Const OpenFileForAppending = 8 
LineOfEquals = "=============================================" & vbCrLf

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set fso = CreateObject("Scripting.FileSystemObject")
sLogPath = strDesktop & "\msval.txt"

Sub ShowHelp
    Wscript.Echo vbCrLf & _
    "About:" & Chr(9) & "Msval.vbs is an XML file validator." & vbCrLf & _
    vbCrLf & _
    "Syntax:" & Chr(9) & "msval [input_file_or_folder]" & vbCrLf & _
    vbCrLf & _
    "Examples:" & vbCrLf & vbCrLf & _
    Chr(9) & "msval my.xml" & vbCrLf & _
    Chr(9) & "msval C:\MyFolderContainingXML" & vbCrLf & _
    Chr(9) & "msval ..\..\MyFolderContainingXML" & vbCrLf & vbCrLf & _
    "Notes:" & Chr(9) & "If XML file is specified, results are " & _
    "returned in a console message." & vbCrLf & vbCrLf & _
    Chr(9) & "If a folder is specified, a report file, Msval.txt," & _
    " is generated" & vbCrLf & _
    Chr(9) & "on your desktop and validation results are recursive" & _
    " for XML" & vbCrLf & _
    Chr(9) & "files found in the specified folder and all of its" & _
    " subfolders." & vbCrLf
    Exit Sub
End Sub

Sub ErrorOut
    Wscript.Echo (vbCrLf & "Status: MSVAL failed." + vbCr)
    Wscript.Quit
End Sub

Sub ValidateAsXmlFile
    Set xmlDoc = CreateObject("Msxml2.DOMDocument.6.0")
    xmlDoc.setProperty "ProhibitDTD", False
    xmlDoc.setProperty "ResolveExternals", True 

    xmlDoc.validateOnParse = True
    xmlDoc.async = False
    xmlDoc.load(strFileName)
    Select Case xmlDoc.parseError.errorCode
       Case 0 
            strResult = "Valid: " & strFileName & vbCr
       Case Else
           strResult = vbCrLf & "ERROR! Failed to validate " & _
           strFileName & vbCrLf & xmlDoc.parseError.reason & vbCr & _
          "Error code: " & xmlDoc.parseError.errorCode & ", Line: " & _
                           xmlDoc.parseError.line & ", Character: " & _
                           xmlDoc.parseError.linepos & ", Source: " & _
                           Chr(34) & xmlDoc.parseError.srcText & _
                           Chr(34) & " - " & Now & vbCrLf 
    End Select

' Create log file for storing results when validatin multiple files.
    Set f = fso.OpenTextFile(sLogPath, OpenFileForAppending)
    f.WriteLine strResult
    f.Close

    ' Increment processed files count.
    procFilesCount = procFilesCount + 1
    'Release DOM document object
    Set xmlDoc = Nothing
End Sub

Function WalkSubfolders(Folder)
    Dim strFolder, currentFolder, strCurPath
    Set currentFolder = fso.GetFolder(Folder)
    strCurPath = currentFolder.Path
    strFolder = vbCrLf & LineOfEquals & _
                "Folder: " & strCurPath & _
                vbCrLf & LineOfEquals & vbCrLf

    ' Open the log file and append current subfolder.
    Set f = fso.OpenTextFile(sLogPath, OpenFileForAppending)
    f.Write strFolder
    f.Close
    strFolder = ""
    Set Files = currentFolder.Files
    If Files.Count  0 Then
      ' Walk the collection. If the file is XML, 
      ' load and validate it.
      For Each File In Files
         strFileName = fso.GetAbsolutePathName(File)
         strFileExt = Right(strFileName,4)
         Select Case strFileExt
           ' Process all known XML file types.
           Case ".xml" ValidateAsXmlFile
           Case ".xsl" ValidateAsXmlFile
           Case ".xsd" ValidateAsXmlFile
           Case Else
         End Select
      Next
    End If

    ' Open the log file and append file list from current subfolder.
    Set f = fso.OpenTextFile(sLogPath, OpenFileForAppending)
    f.Write strFiles
    f.Close
    strFiles  = ""

    Set SubFolders = currentFolder.SubFolders

    If SubFolders.Count  0 Then
       For Each SubFolder In SubFolders
          strFolder = strFolder & WalkSubfolders(SubFolder)
       Next
       strFolder = strFolder & vbCr
    End If
End Function

Sub WriteEOFSummary
    Set f = fso.OpenTextFile(sLogPath, OpenFileForAppending)
    strResult = vbCrLf & LineofEquals & _
               "Processing completed at " & Now & vbCrLf & _
               procFilesCount & " files processed" & vbCrLf & _
               LineOfEquals
    f.Write strResult
    f.Close
    strResult = "Results written to " & sLogPath & vbCrLf & _
               "Files processed: " & procFilesCount & vbCrLf & _
               vbCrLf & "Do you want to view the results now?"
    MsgBox strResult, vbYesNo, "MSVAL: Processing completed"
    If vbYes Then
       WshShell.Run ("%windir%\notepad " & sLogPath)
    End If
End Sub

Function ProcessStandAloneFile(sFile)
    Dim basename, str, xdoc
    Set f = fso.GetFile(fspec)
    basename = f.Name
    ' Load XML input file & validate it
    Set xdoc = CreateObject("Msxml2.DOMDocument.6.0")
    xdoc.setProperty "ProhibitDTD", False
    xdoc.setProperty "ResolveExternals", True
    xdoc.validateOnParse = True
    xdoc.async = False
    xdoc.load(fspec)
    If xdoc.parseError.errorCode = 0 Then
       str = basename & " is valid"
    ElseIf xdoc.parseError.errorCode  0 Then
       str = basename & " is not valid" & vbCrLf & _
       xdoc.parseError.reason & " URL: " & Chr(9) & _
       xdoc.parseError.url & vbCrLf & "Code: " & Chr(9) & _
       xdoc.parseError.errorCode & vbCrLf & "Line: " & _
       Chr(9) & xdoc.parseError.line & vbCrLf & _
       "Char: "  & Chr(9) & xdoc.parseError.linepos & vbCrLf & _
       "Text: "  & Chr(9) & xdoc.parseError.srcText
    End If
    ProcessStandAloneFile = str
End Function

Sub Main
    'Initialize files count
    procFilesCount = 0

    ' Get the folder to scan for files.
    If Wscript.Arguments.Length > 0 Then
       fSpec = Wscript.Arguments.Item(0)
       fSpec = fSpec & "\"
    Else
       ShowHelp
       WScript.Quit
    End If

    fspec = fso.GetAbsolutePathName(fspec)
    If fso.FileExists(fspec) Then
       strResult = ProcessStandAloneFile(fspec)
       Wscript.Echo strResult
       Wscript.Quit
    ElseIf fso.FolderExists(fspec) Then
       ' Executes a 'DIR' command into a collection.
       Set dir = fso.GetFolder(fspec)
       Set coll = dir.Files
       ' Create the log file on the user's desktop.
       Set f = fso.CreateTextFile(sLogPath, 1)
       strResult = vbCrLf & LineofEquals & sLogPath & _
           " at " & Now & vbCrLf & LineOfEquals & vbCrLf
       f.Write strResult
       f.Close
       WalkSubfolders(fSpec)
    Else
       strResult = vbCrLf & "Input file or folder " & _
                   fspec & " does not exist."
       MsgBox strResult, vbOKOnly, _
             "MSVAL: File or folder doesn't exist"
        ErrorOut
    End If

    WriteEOFSummary

    ' Reset object variables.
    Set fso = Nothing
    Set xmlDoc = Nothing

End Sub

http://msdn.microsoft.com/en-us/library/ms756015(VS.85).aspx