XML and validation

S

stefan.sp

I have 2 big problems with an XML Validation:

First I want to load an XML File, attach a XSL Schema and validate it:

Set xmdoc = Documents.Open(filename)
'schema anbinden
blnSchemaAttached = False
For Each objNS In Application.XMLNamespaces
If objNS.URI = uriSchema Then
'objNS.AttachToDocument xmdoc
blnSchemaAttached = True
Exit For
End If
Next

If blnSchemaAttached = False Then
'xmdoc.XMLSchemaReferences.Add "bbreport.xmlref.sp", "bbreport",
pathSchema, True
Set objNS = Application.XMLNamespaces.Add(pathSchema, uriSchema,
"bbreport", True)
End If
objNS.AttachToDocument xmdoc
xmdoc.XMLSchemaReferences(uriSchema).Reload
xmdoc.XMLSchemaReferences.AutomaticValidation = True

'Schemaverletzungen prüfen
xmdoc.XMLSchemaReferences.Validate
If xmdoc.XMLSchemaViolations.count > 0 Then ' ValidationStatus <>
wdXMLValidationStatusOK Then
MsgBox "error"
End If

But it's not possible to validate, the code doesn't recognize not valid xml
Files.

The second problem comes creation a new file:

I create e new file and want to attach an existing schema.

Set formdoc = ActiveDocument
'neues dok und Schema anbinden
Set xmdoc = Documents.Add
xmdoc.XMLSaveDataOnly = True
blnSchemaAttached = False
For Each objNS In Application.XMLNamespaces
If objNS.URI = uriSchema Then
'objNS.AttachToDocument xmdoc
blnSchemaAttached = True
Exit For
End If
Next
If blnSchemaAttached = False Then
Set objNS = Application.XMLNamespaces.Add(pathSchema, uriSchema,
"bbreport", True)
'xmdoc.XMLSchemaReferences.Add "bbreport.xmlref.sp", "bbreport",
pathSchema, True
'objNS.AttachToDocument xmdoc
End If
xmdoc.XMLSchemaReferences(uriSchema).Reload

In the last line I get an Error, I dont understand. It seems, like I need
another XML Schema beside my own Schema to save the doc.

It would be very nice, if someone had any ideas for me

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top