Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Office Content Control Schema Violations

0 views
Skip to first unread message

Greg Maxey

unread,
Nov 9, 2009, 7:58:55 AM11/9/09
to
Hi,

Taking a shot in the dark here in hopes someone may have a solution.

I attempting to validate the data entered in Microsoft Word Content Controls
(CC) using an attached schema. I can map a CC to a CustomXMLPart, attach a
schema and detect violations. CC schema violations are flagged in the
document with a red dashed box outline.

Does anyone know how to count those boxes programmatically or otherwise
determine if one or more CC schema violations exist in a document?

My real objective is to create functional, robust CC validation process.
The schema validation method works great, but it has no teeth so to speak.
All it does
is flag the violations. If I could somehow count those violations then I
could prevent a user from doing things like save, print, etc until valid
entries are present.

There is a property:

ActiveDocument.XMLSchemaViolations that I could use for this purpose. For
example, I could prevent saving the document using:

Sub FileSave()
If ActiveDocument.XMLSchemaViolations.Count > 0 Then
MsgBox "Please correct errors before attempting to save or print this
document."
Exit Sub
Else
ActiveDocument.Save
End If
End Sub

This counts document schema violation (i.e., XML tags applied directly to
plain text in the document), but this doesn't detect violations in Content
Controls.

I have also tried applying the XML tags directly to the CC range. But
again, the violations are not detected. I don't know that much about XML so
I could be applying the tags incorrectly.

I have posted some pictures on my website to illustrate the problem.


http://gregmaxey.mvps.org/images/Schema violations.png

Sub CountViolaion()
MsgBox ActiveDocument.XMLSchemaViolations.Count
End Sub


Returns 1. There are clearly 2 violations present.

http://gregmaxey.mvps.org/images/No schema violations.png

Sub CountViolaion()
MsgBox ActiveDocument.XMLSchemaViolations.Count
End Sub


Returns 0. Actual conditions.

http://gregmaxey.mvps.org/images/Problem validation.png


Sub CountViolaion()
MsgBox ActiveDocument.XMLSchemaViolations.Count
End Sub


Returns 0. Now it doesn't even detect the direct XML tags.

If I could somehow detect programmatically the schema violation shown in the
last illustration then I could add some teeth to my validation process.

Thanks for your interest and replies.


--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

Arrogance is a weed that grows mostly on a dunghill (Arabic proverb)

Greg Maxey

unread,
Nov 9, 2009, 8:16:14 AM11/9/09
to
0 new messages