none
Add schema to CustomXMLPart RRS feed

  • Question

  • Edited 6/20/2011

    I have created and added a CustomXMLPart to my document.  I have also created an .xsd schema file that I would like to use to validate the XML. 

    Using VBA the user can access data in the customXMLPart or change existing data:

    For example the following code lets a user modify date for an employee:

    Sub SetNodeData()
    'Set node data (e.g., hiredate) for a specific employee (e.g. employee ID 003)
    Dim pData As String
    If Len(Selection.Text) > 1 Then
      pData = Selection.Text
    Else
      pData = InputBox("Enter node data", "NODE DATE INPUT")
    End If
    If Not SetXMLStringData(PERSONNEL, "003", "hiredate", pData) = True Then
      MsgBox "A data node matching this criteria was not found", vbOKOnly
    End If
    End Sub

    The hiredate should be a valid date.  As it is, the user could select any text or enter any value in the input box and that value is written to the node.  For example if the user enters "last week" in the input box and runs the code the corresponding node value is changed to:

    <employee id="003">
            <firstname>Mary</firstname>
            <lastname>Miller</lastname>
            <hiredate>last week</hiredate>
        </employee>

    I am looking for a way to prevent invalid data entry using a schema (I know that I could check for a valid date before running the code.)

    I have tried to add the schema to the customXMLPart schema collection:

    Sub AddSchema()
    ActiveDocument.CustomXMLParts(4).SchemaCollection.Add NamespaceURI:=CUST_NAMESPACEURI, FileName:="D:\Data Stores\CompanyData XSD (Schema) Validation.xsd"
    End Sub

    This code (an every other variation I can think of) consistently returns an error:  "The schema cannot be reloaded, as the schema collection is currently in use."

    I manually added the schema to the document XML schema collection using Developer>XML>Schema>Add Schema.  I also confirmed the schema does validate a hiredate node in the document  (I manually added a hiredate node to the document text with invalid data and it was underlined).

    I manually confirmed (or a least think I confirmed) that even though the schema is in the document schema collection it is not being used by the CustomXMLPart:

    Sub CheckForValidationErrs()
    Dim ValErrors As CustomXMLValidationErrors
    Dim ValError As CustomXMLValidationError
    Dim cxp1 As CustomXMLPart
    With ActiveDocument
      Set cxp1 = .CustomXMLParts(4)
      Set ValErrors = cxp1.Errors
    End With
    If ValErrors.Count > 0 Then
       For Each ValError In ValErrors
          Debug.Print ("Error name: " & ValError.Name & " Error description: " & ValError.Text)
       Next
    End If
    End Sub

    So here is where is stands.  1) I have a customXMLPart loaded in my document that has a node (hiredate) with invalid data (if checked against a schema).  2) When I try to add the schema to the CustomXMLPart schema collection I get an error that says the schema cannot be reloaded, as the schema collection is currently n use. 3) Adding the schema to the document collection doesn't seem to have any bearing on the CustomXMLPart XML. 4) The entire Office/Word help on this and other CustomXMLPart methods and properties is full of half baked examples that don't work.

    Can anyone show me how to add a schema to a CustomXMLPart so a0 that any attempt to make invalid (schema violation) changes to the XML are deteted and prevented or b) detect invalid enteries in the XML after a change is made.

    A pointer to a working example using the CustomXMLSchemaCollection and CustomXMLValidationErrors would be grand.

    Thanks.

     


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    • Edited by Greg Maxey Monday, June 20, 2011 12:34 PM clarification and detail
    Monday, June 20, 2011 1:48 AM

All replies

  • Hi Grey,

    We are doing the research about your problem. There might be some delay about the response. Appreciate your patience.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 21, 2011 7:25 AM
  • Bruce, Thanks for your reply.  If needed I can send you the document, the external XML that I load as the XMLPart and the schema .xsd file.
    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    Tuesday, June 21, 2011 11:53 AM
  • AFAIK the situation is this:

     a. Office maintains a persistent collection of "user-defined schemas" (i.e. the "Schema Library" that you can access via Word->Templates and Addins->XMLSchema). In Word, it was originally used for working with "Custom XML in the document", i.e. the sort that doesn't really have anything to do with CustomXML Parts and which has been affected by the i4i judgment, or for stuff like Smart Documents.

     b. Word also associates other schema collections with, e.g. the core properties and ContentType properties (i.e. the sort you can define in Sharepoint).

     c. The only way I have managed to associate a Schema with a CustomXML Part in the Word object model is to do it when the part is created, e.g.

    Sub AddSchema()

    Dim objCXSC As New Office.CustomXMLSchemaCollection

    Dim s As String

    s = "the XML for your CustomXMLPart"

    ' The following if the .xsd is already in the Schema Library

    objCXSC.Add NamespaceURI:=CUST_NAMESPACEURI

    ' or the following if it isn't

    objCXSC.Add FileName:="D:\Data Stores\CompanyData XSD (Schema) Validation.xsd"

    ActiveDocument.CustomXMLParts.Add s, objCXSC

    End Sub

    If you can do that, then Word will start displaying validation information when the user puts data in the content controls, and change the box round the control into a dashed rather than solid box when validation fails. But AFAICS, Word does not stop the suer from existing the field or saving/closing the document.

    (I thought we'd (can't remember who) been through all that stuff a long time ago and had determined that Word just didn't do validation)

    d. However, when you are working with Sharepoint, Sharepoint properties are stored in a CustomXMLPart and have complex schema information associated with them. When Word opens the document, the Part has a SchemaCollection that references at least 11 schemas. Content controls associated with data in /those/ parts. Word displays similar validation information. It still doesn't force the user to correct data on a field-by-field basis. It does force compliance with the schema when you try to save back to the server, but /not/ if you save to a local folder (for example).

    e. I wondered if it might be possible to "copy" the SchemaCollection associated with a SharePoint ContentType, and associate it with my own non-Sharepoint CustomXMLPart instead. Obviously I'd have to use the same schema as the Content Type. It certainly seems to be possible to do that, but in that case Word does not appear to enforce the schema at all - it doesn't even show validation info.

    Of course it's always possible that I've got things wrong in my experiments and that such-and-such is possible, but it seems to me that

     a. anything approaching what you might hope for from a validation feature is only really there in the SharePoint environment

     b. although you could define your CustomXMLParts to look like Sharepoint content controls even outside Sharepoint,

        - I'm not sure it is advisable

        - I don't know whether you can have more than one such Part

        - You don't appear to get any additional validation features

    There's a patent application at

    http://www.patentgenius.com/patent/7752224.html

    which seems to provide marginally better documentation of the intended operations than I've seen elsewhere, although one or two of the exemplay names are different in the Word 2007/2010 product. But it still leaves a lot of question open as to exactly what the original designers had in mind, and whether Word 2007/2010 is actually behaving the way it is supposed to or not.

    FWIW when I was dealing with the Schema Library a lot more several years ago, it was quite "touchy" and you seemed to have to close down Office applications to avoid problems in some cases for a modified schema to be correclty recognised. But I think that was back in the Word 2003 era.

    Anyway, I hope the Microsoft people can come up with something more definitive than that.

     

     


    Peter Jamieson
    Tuesday, June 21, 2011 11:01 PM
  • Peter,

    Thanks.  This is a lot to look at.  It is late and I have long trip tomorrow.  I will get back to you.

     


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    Wednesday, June 22, 2011 1:24 AM
  • Greg,

    It is late

    Yes, it was here too. This morning I ran your CheckForValidationErrs code against my own example (with the CustomXMLPart associated with a schema in the Schema Library and it did pick up the error(s) as you might expect. So there is hope!


    Peter Jamieson
    Wednesday, June 22, 2011 8:26 AM
  • Hi Peter

    <<c. The only way I have managed to associate a Schema with a CustomXML Part in the Word object model is to do it when the part is created>>

    Thanks for this - that's the key point I never can remember!

    FWIW I think they're going to have to do something with content controls if they want to "migrate" people from the now-defunct XML-Nodes. So perhaps we'll see something with this, at some point.


    Cindy Meister, VSTO/Word MVP
    Wednesday, June 22, 2011 12:22 PM
    Moderator
  • Thanks for this - that's the key point I never can remember!
    Sometimes it helps not to be able to remember anything :-)
    I notice that in the patent application there was an EnforceStructure property in the CustomXMLSchemaCollection class/object. That seems to have fallen by the wayside at some point - perhaps it was "nice in theory" but fell foul of reality. Or maybe that's in another object somewhere now.

    Peter Jamieson
    Wednesday, June 22, 2011 1:55 PM
  • Peter,

     

    "EUREKA!!" What else can I say? Your point  "c. The only way I have managed to associate a Schema with a CustomXML Part in the Word object model is to do it when the part is created." has been like a flash of light.  The chains of ignorance have fallen away and I have managed to gain a little better understanding of XML and how to bend customXMLParts to my will.

    Unfortunately it seems that given "c" the only way to define the XML in a customXMLPart is to do it with teh .Add method as well.  If the optional XML paramenter in the .Add method is left empty and I try to later use .LoadXML or .Load the pointer to the schema seems to be lost.

    You are correct.  You and I looked at validating Content Controls using an attached schema several years ago and until now I was resigned to belief that a schema could be used to validate CC entries (or flag invalid data with the red border) but that there was no way to ensure only valid data.  We were wrong!!

    I wasn't even thinking of CCs and validation when I posted.  I was actually just toying with using customXMLParts as a document storage location for users to store source data for populating userforms.  Once, thanks to your tip, I discovered that I could physcially check for and detect schema errors with code though I thought maybe I could find a way to add some teeth to CC validation.

    The following code is used to 1) Add a customXMLPart 2) Associate a schema to the part 3) User the schema is attached to the document.

    Option Explicit
    Global Const CUST_NAMESPACEURI = "http://CCValidation.com"
    Private Const XML_SOURCE As String = "D:\Data Stores\CC Validation using Schema (Robust) XML Script.txt"
    Dim oCustPart As CustomXMLPart
    Sub SetXML()
    'Run this code to clear and reload the external XML script file.
    Dim oCustXMLPartSC As New Office.CustomXMLSchemaCollection
    Dim pXML As String
    'Get the XML from a file (We can't use the .Load method because the SchemaCollection must be defined when the customXMLPart is added.)
    pXML = GetXMLStringFromFile
    On Error Resume Next
    'If the schema isn't already a part of the schema library then add it
    oCustXMLPartSC.Add FileName:="D:\Data Stores\CC Validation using Schema (Robust).xsd"
    'If it is an error occurs.  Handle the error and use the schema as defined in the schema libary.
    If Err.Number = -536602606 Then
      oCustXMLPartSC.Add NamespaceURI:=CUST_NAMESPACEURI
    End If
    'Make sure schema is attached to the document.
    Application.XMLNamespaces.Item(Index:=CUST_NAMESPACEURI).AttachToDocument Document:=ActiveDocument
    'See if the customXMLPart is already defined
    Set oCustPart = ActiveDocument.CustomXMLParts.SelectByNamespace(CUST_NAMESPACEURI).Item(1)
    'If it is delete it.
    If Not oCustPart Is Nothing Then oCustPart.Delete
    'Add the customXMLPart and associate the schema
    Set oCustPart = ActiveDocument.CustomXMLParts.Add(XML:=pXML, SchemaCollection:=oCustXMLPartSC)
    'Store the unique CustomXMLPart ID for future reference
    ActiveDocument.Variables("custPartID").Value = oCustPart.ID
    'oCustPart.Load XML_SOURCE (this won't work because there doesn't appear to be any way to associate a schema except when the part is created)
    'Debug.Print oCustPart.SchemaCollection.Item(1).Location 'For testing
    Set oCustPart = Nothing
    End Sub
    Function GetXMLStringFromFile() As String
    'Requires a reference to the Microsoft Scripting Runtime
    Dim oFSO As FileSystemObject
    Dim pStrIn As TextStream
    Dim pStrFile As String
    Dim pStr As String
    pStrFile = XML_SOURCE
    Set oFSO = New FileSystemObject
    Set pStrIn = oFSO.OpenTextFile(pStrFile, 1)
    Do While Not pStrIn.AtEndOfStream
        pStr = pStr + pStrIn.ReadLine
        pStr = pStr + vbLf
    Loop
    pStrIn.Close
    Set oFSO = Nothing
    GetXMLStringFromFile = pStr
    End Function

    The XML contains nodes for employee data e.g., name, age, hiredate, and ssn

    The schema validates the name (length), age (0-110), hiredate (date), and ssn(###-##-####)

    I added for CCs titled "Name", "Age", "Hire Date" and "SSN" to the document and mapped them to the respective nodes:

    Sub Map_the_CCs()
    Dim oCC As ContentControl
    Set oCustPart = SetXMLPartByNameSpaceURI_And_RootElement(ActiveDocument, CUST_NAMESPACEURI, "Personnel")
    Set oCC = ActiveDocument.SelectContentControlsByTitle("Name").Item(1)
    oCC.XMLMapping.SetMapping "/ns0:Personnel[1]/ns0:employee[1]/ns0:name[1]"
    Set oCC = ActiveDocument.SelectContentControlsByTitle("Age").Item(1)
    oCC.XMLMapping.SetMapping "/ns0:Personnel[1]/ns0:employee[1]/ns0:age[1]"
    Set oCC = ActiveDocument.SelectContentControlsByTitle("Hire Date").Item(1)
    oCC.XMLMapping.SetMapping "/ns0:Personnel[1]/ns0:employee[1]/ns0:hiredate[1]"
    Set oCC = ActiveDocument.SelectContentControlsByTitle("SSN").Item(1)
    oCC.XMLMapping.SetMapping "/ns0:Personnel[1]/ns0:employee[1]/ns0:ssn[1]"
    End Sub

    Here is the neat part.  Since I can now detect schema violations with code I can enforce CC validation (i.e., until the user gets it right he or she can't exit the CC):

    Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
    Dim pStrTemp As String
    Dim i As Long
    Select Case CC.Title
      Case "Name", "Age", "Hire Date", "SSN"
        If CC.ShowingPlaceholderText Then Exit Sub
        If CC.XMLMapping.CustomXMLPart.Errors.Count > 0 Then
          For i = 1 To CC.XMLMapping.CustomXMLPart.Errors.Count
            If CC.XMLMapping.CustomXMLPart.Errors(i).Node.XPath = CC.XMLMapping.XPath Then
              Beep
              Cancel = True
              CC.Range.Select
              Exit Sub
            End If
          Next i
        End If
      Case Else
    End Select
    End Sub

    Or even more draconian:

    Sub FileSave()
    If ValidationErrors Then
      MsgBox "Please resolve validation errors before attempting to save this file."
    Else
      ActiveDocument.Save
    End If
    End Sub

    Function ValidationErrors() As Boolean
    ValidationErrors = False
    Dim ValErrors As CustomXMLValidationErrors
    Dim ValError As CustomXMLValidationError
    Dim cxp1 As CustomXMLPart
    With ActiveDocument
      Set cxp1 = ActiveDocument.CustomXMLParts.SelectByNamespace(CUST_NAMESPACEURI).Item(1)
      Set ValErrors = cxp1.Errors
    End With
    If ValErrors.Count > 0 Then
       ValidationErrors = True
    '   For Each ValError In ValErrors
    '      Debug.Print ("Error name: " & ValError.Name & " Error description: " & ValError.Text)
    '   Next
    End If
    End Function

    Thanks a heap for taking interest in this post.  It is really a good feeling to finally find a solution to an objective I have sought and fumed over for years.  I will be tinkering with this a bit more to see if I can find some other tricks.

    It would be great if MS would take interest as well and fix issues like your "c."  It would be even better if they would toss all the half-baked and non-functional examples they provide in the help files.

    I can send you my working file if you wish.  Thanks again.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    Thursday, June 23, 2011 2:46 AM
  • Greg,

    Glad it worked out.

    Yes, I think we probably came to the wrong conclusion "last time."

    There is of course another way that you could approach the validation, although

     a. I haven't tried it

     b. you wouldn't get any of the UI support for custom controls (dashed lines and error "tips"). And that is probably quite valuable.

    That would be to put the schema XML in another CustomXMLPart, extract the XML, the XSD in the usual way, and use a regular XML parser to do the validation.

    The appeal of doing it that way is that a copy of the schema would travel with the document (so a drawback would be the proliferation of copies) and you would never have to touch the user's Schema Library. 

    Looking at the Patent, it seems to me that a key notion was that Word should be actively trying to ensure that the XML in a CustomXMLPart was valid. I suspect that might have proven limiting and the idea may have been watered down. 


    Peter Jamieson
    Thursday, June 23, 2011 3:19 PM
  • Peter,

    Thanks. When it comes to XML, XSD, Sharepoint, Parsers and the like, you really know what you are talking about and I am just bumbling along in the dark.  If I sound dumb, I am.  Your suggested alternative method flew over my head. That is ok though because I am only tinkering and don't really need the benefits your proposal might bring.

     


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    Thursday, June 23, 2011 11:15 PM
  • Greg, if it helps you i have been using software to validate my XSD against my xml files, if you're not too hot on xml that might be the way to go . There are tons of free ones out there, the one i use is called liquid xml editor.

    Friday, June 24, 2011 12:50 PM
  • Paul,

    Thanks.  I look at that.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    Friday, June 24, 2011 9:07 PM
  • Hi Greg,

    How's the problem now?  If you need any further assistance, please feel free to let us know.

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Monday, June 27, 2011 1:39 AM
    Moderator
  • The problem is still the problem.  Your object model doesn't work with the methods you have provided and your help files on the subject are a disaster.

     


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    Monday, June 27, 2011 9:31 AM
  • Hi Greg,

     

    I’ve reviewed the posts on this thread.

    You replied:

    "EUREKA!!" What else can I say? Your point  "c. The only way I have managed to associate a Schema with a CustomXML Part in the Word object model is to do it when the part is created." has been like a flash of light.

     

    Do I understand correctly, that if you associate the Schema with a CustomXML Part when the part is created, your code works as expected?

     

    Then you said:

    It would be great if MS would take interest as well and fix issues like your "c."  It would be even better if they would toss all the half-baked and non-functional examples they provide in the help files.

     

    Can you please provide links or other specifics on the non-functional help or web examples you referenced while trying to implement your code?

     

    I’ll gladly follow up with the content team regarding the specific content you’d like to see improved.

     

    How else can I help you with this issue?

     

    As you may know, you can make requests/complaints about your developer experience directly to the Office product team via: http://support.microsoft.com/contactus/?ws=support&ctt=114&ws=support#tab5

     

    Then click on the link titled:

    Office Product Feedback

     

    Regards,

    Bill


    Bill Go - MSFT
    Wednesday, June 29, 2011 11:49 PM
    Answerer
  • Bill,

     

    Thank you very much for your interest.

    Yes my code works correctly when modified as Peter suggests.

    I replied "EUREKA" in respone to Peter Jamieson's observation:


    <<c. The only way I have managed to associate a Schema with a CustomXML Part in the Word object model is to do it when the part is created>>

    He is right but being right there seems to be a lot wrong with the object and methods.  Why can it only be added when the part is created?  The methods are there that make one think that is should be possible to add one anytime:

    Sub ScratchMacro()
    Dim oXMLPart As CustomXMLPart

    'Create the part
    Set oXMLPart = ActiveDocument.CustomXMLParts.Add("<Test></Test>")

    'Then associate a schema
    oXMLPart.SchemaCollection.Add NamespaceURI:="http://CCValidation.com", _
         FileName:="D:\Data Stores\CC Validation using Schema (Robust).xsd"
    End Sub

    As noted above this causes an RTE that the schema collection is already loaded.

    Be limited to associate a schema "only" when the part is added means that you have to define the entire part when it is created.  I was unable to simply create the part with a simple XML string and then later completely load a long XML script using LoadXML.

    "Can you please provide links or other specifics on the non-functional help or web examples you referenced while trying to implement your code?"

    Bill have you ever looked at the help files provided for working with the customXMLPart in general?  There awful.  Here is just one example.

    Example
    The following example demonstrates adding a custom XML part, selecting a part with a namespace URI, and then selecting a node within that part that matches an XPath expression.

    Visual Basic for Applications
    Dim cxp1 As CustomXMLPart
    Dim cxn As CustomXMLNode
    
    ' Add a custom xml part.
    ActiveDocument.CustomXMLParts.Add "<supplier>"
    
    ' Return the first custom xml part with the given namespace.
    Set cxp1 = ActiveDocument.CustomXMLParts("urn:invoice:namespace")    
    
    ' Get a node using XPath.               
     Set cxn = cxp1(1).SelectSingleNode("//*[@supplierID = 1]")
    

    Try adding that code to a Word document and check out the results.

    It errors on the first line:  RTE "The following tags where not closed/supplier"

    Fix that:

    ActiveDocument.CustomXMLParts.Add "<supplier/>"

    and it errors on the second line:

    RTE-9 Sub-Script out of range

    Fix that:

    ActiveDocument.CustomXMLParts.Add "<supplier xmlns='http://invoice'/>"
    Set cxp1 = ActiveDocument.CustomXMLParts("http://invoice")

    and it errors on the third line RTE 438 object doesn't support this property or method.

    At this point the person looking to get help is only getting frustrated.

    Fix that

    Dim cxp1 As CustomXMLPart
    Dim cxn As CustomXMLNode
    ActiveDocument.CustomXMLParts.Add "<supplier xmlns='http://invoice'><company supplierID='1'>Acme Hardware</company></supplier>"
    Set cxp1 = ActiveDocument.CustomXMLParts("http://invoice")
    Set cxn = cxp1.SelectSingleNode("//*[@supplierID = 1]")

    and you finally have a working example.

    My point being when I first visited help for "SelectSingleNode" I didn't know how to fix any of the errors and was only frustrated.

    Then help if full of non-functional examples like the one above.  It would be so much better if the help contained functional examples.

     

    Thanks.

     


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    Thursday, June 30, 2011 1:53 AM
  • Bill, thanks for your post.

    I would like to provide a more positive response to your post, but it is difficult to know where to start.

    For example, asking people for specific links is all very well, but please try to think about what is happening from the developer's/support person's point of view.

    When responding to Greg, I searched around some articles, none of which were particularly helpful. I cannot now remember how many were Microsoft ones, and how many were posts/replies on developer sites. I don't actually remember seeing a clear statement anywhere that the association with a Schema Collection had to be made at the time the CustomXMLPart was created, for example. The clearest indication of that that I can remember actually came from the Patent text! But why would I create a list of all those "not very useful" pages? I would only do that if /at the time/ I was gathering information, I had time to do that /and/ I knew that something useful might happen if I reported the problems. Further, going back through my browser history to gather page information would take a substantial effort, particularly since I use multiple systems and multiple browsers.

    The horrible reality of providing feedback in any form to Microsoft (and it certainly isn't just Microsoft) is that

     1. most of the places you can do it, it's a one-way, "fire and forget" operation.

     2. experience suggests that nothing ever happens as a consequence, which leads to the hypothesis that the effort making a post is a complete waste of time, and that it is not inconceivable that posts are going into a bitbucket or that the volume of feedback is so large that the chances of a single post being read/actioned are extremely small.

    As far as (1) is concerned, I think we probably all understand that

     a. Microsoft (and other companies) are business, not charities and cannot do everything for nothing.

     b. it is probably extremely difficult to cope with the volume of feedback received

     c. Microsoft does not really want to acquire identification information (which it probably then has a legal obligation to care about) when people post feedback.

    As far as (2) is concerned, the problem is that there is no feedback of any kind. You can of course try to reassure people that their feedback is all read, triaged and dealt with. I have even heard that is the case (for some business units) from people I generally trust. But although I do still occasionally post such stuff, deep down I assume that it is probably a waste of time.

    Just by way of example, I have probably provided between 5 and 10 pieces of technical feedback via the Mac Word 2011 feedback option since the product came out. In most cases, I would have prepared a "proper" problem submission, with a title, description, steps to reproduce, and so on. IME there is little point in doing less than that, because a person at the other end probably cannot do anything with it.  Further, there is usually no place in the page to post example files etc., so I'd either have to put them on one of my sites (indefinitely) or describe how to create those files. So doing it "properly" takes a lot of time and effort. Even writing this response has taken a lot of time.

    And the problem with that is that I may have spent a lot of time and effort describing something that the dev. team already knows, or has no intention of changing. At least during beta testing it was (sometimes) possible to discover whether a problem had been reported, and/or acquire some sort of problem ID, and/or you would at least sometimes get some sort of response. But none of those things occurs with the current mechanisms.

    As another example, you may not even realise that the mechanisms for providing product feedback and support can vary somewhat from region to region/country to country. For example I found it impossible to find warranty support via email for Mac Word 2011 here in the UK, but attempts to go via the US system also failed. Only a phone call would do. Even if I follow the link you provided for Office support, there is a difference between the US and UK versions of the page - in the US, it's feedback about Office, leading to a box where you get to specify the version. In the UK, the link is for "Office 2007". What do people who have Office 2010 actually do? When I see that, my initial response is "no-one's maintaining these pages - what chance is there that they'll be looking at the feedback? And if it's UK people looking at the feedback, what connection do they have to the US dev. teams?" In fact, ISTR providing feedback about these UK pages sometime last year, but I do not know if anything has changed as a result :-;

    Personally, I think Microsoft could usefully...

     a. start to recognise who its "friends" are. And I don't mean people who are necessarily well-disposed towards the company. I mean people who are demonstrably capable of providing good feedback etc., and perhaps would even be willing to sign an NDA if necessary, as long as there is a two-way mechanism. AIUI, that what Connect was for, but it just does not appear to cover areas such as Office (perhaps it does now?)

     b.publish some stats. I, for one would find it very useful to have some idea about how much feedback Microsoft has to process. 

     c. provide some "this is what we do with your feedback" examples, e.g. as web pages, as a video, etc.

     d. provide some examples of the kind of feedback that you can actually do something with (well, OK, perhaps "your product is awful" is useful feedback too, but for technical issues, providing a standardised form that encourages people to provide a title, description, version info. etc.) would probably be useful both for us and for you.

    In terms of specific content (not to do with the CustomXMLPart problem) that I have come across recently while posting in these groups, here is /one/ example:

    http://msdn.microsoft.com/en-us/library/aa537149(v=office.11).aspx

    The following statement appears to me to be misleading (the author is probably thinking about inserting a table using InsertDatabase or some other mechanism)

    Note:
    Place the content of each field within a pair of single or double quotes if the field or record delimiter could be part of the field data.

    FWIW when I see material like this, I tend to go through the following thought processes:

     a. it doesn't seem to work here

     b. maybe it only works on older versions of Word (and I check, and that takes time)

     c. is there something else I am doing wrong? (How would I find out?)

     d. whoever created this article cannot have tested this

     e. what workarounds/alternative approaches can I think of

    As a "support guy", it's (d) that really irritates me more than anything, because it's /your/ documentation, for /your/ product, that people in /your/ company are paid to produce, document and support. You are not paying me, but dealing with your errors uses a considerable amount of /my/ time.


    Peter Jamieson
    Thursday, June 30, 2011 8:10 AM
  • Peter,

    Thanks for posting.  I don't know what you felt was negative in my reply or maybe I was reading a hidden message that wasn't there.  I didn't mean for my reply to be negative only to convey:

    1. Just because my code now works because of your information about associating a schema only when the part is created, doesn't me that the issus is fixed.

    2.  The help files related to dealing with the customXMLParts published by MS forare hopelessly frustrating and unhelpful.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    Thursday, June 30, 2011 10:32 AM
  • Hi Greg,

    My comments were intended to be in response to Bill's, and my comment about positive/negative had nothing to do with anything you wrote. It's just that I was aware that I wasn't giving Bill any references to the kind of stuff he was actually asking about.

    As you can probably tell from my message, I have seen plenty of unhelpful documentation/examples on Microsoft sites and elsewhere - in fact a reasonable number of posts in these groups seem to be from people who tried such-and-such an example but couldn't get it to work. It's not /always/ the documentation that's at fault, of course! And I certainly do not think that the creation and maintenance of good documentation and examples is easy.

    Peter


    Peter Jamieson
    Thursday, June 30, 2011 3:59 PM
  • Peter,

     

    Copy all.  Thanks.


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    Thursday, June 30, 2011 10:00 PM
  • Hi Greg and Peter,

     

    Thank you both for your candid and thoughtful replies regarding the broken code examples and your input to improve them.

     

    I’ve logged the issue with the specific sample code being broken with the Office development group. I’ve also included the overall sentiment that you both provided regarding how frustrating it is when Microsoft supplied code examples your rely on are broken.

     

    Thanks again to both of you for your efforts to provide constructive feedback, and for your ongoing efforts to help the Word/Office community at large with their Microsoft Office challenges/custom solutions.

     

    Regards,


    Bill Go - MSFT
    Sunday, July 10, 2011 2:37 AM
    Answerer
  • Bill,

    Thanks for getting back to us on this. 


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm
    Sunday, July 10, 2011 3:58 AM
  • Bill,

     

    Thank you very much for your interest.

    Yes my code works correctly when modified as Peter suggests.

    I replied "EUREKA" in respone to Peter Jamieson's observation:


    <<c. The only way I have managed to associate a Schema with a CustomXML Part in the Word object model is to do it when the part is created>>

    He is right but being right there seems to be a lot wrong with the object and methods.  Why can it only be added when the part is created?  The methods are there that make one think that is should be possible to add one anytime:

    Sub ScratchMacro()
    Dim oXMLPart As CustomXMLPart

    'Create the part
    Set oXMLPart = ActiveDocument.CustomXMLParts.Add("<Test></Test>")

    'Then associate a schema
    oXMLPart.SchemaCollection.Add NamespaceURI:="http://CCValidation.com", _
         FileName:="D:\Data Stores\CC Validation using Schema (Robust).xsd"
    End Sub

    As noted above this causes an RTE that the schema collection is already loaded.

    Be limited to associate a schema "only" when the part is added means that you have to define the entire part when it is created.  I was unable to simply create the part with a simple XML string and then later completely load a long XML script using LoadXML.

    "Can you please provide links or other specifics on the non-functional help or web examples you referenced while trying to implement your code?"

    Bill have you ever looked at the help files provided for working with the customXMLPart in general?  There awful.  Here is just one example.

    Example
    The following example demonstrates adding a custom XML part, selecting a part with a namespace URI, and then selecting a node within that part that matches an XPath expression.

    Visual Basic for Applications
    Dim cxp1 As CustomXMLPart
    Dim cxn As CustomXMLNode
    
    ' Add a custom xml part.
    ActiveDocument.CustomXMLParts.Add "<supplier>"
    
    ' Return the first custom xml part with the given namespace.
    Set cxp1 = ActiveDocument.CustomXMLParts("urn:invoice:namespace")    
    
    ' Get a node using XPath.               
     Set cxn = cxp1(1).SelectSingleNode("//*[@supplierID = 1]")
    

    Try adding that code to a Word document and check out the results.

    It errors on the first line:  RTE "The following tags where not closed/supplier"

    Fix that:

    ActiveDocument.CustomXMLParts.Add "<supplier/>"

    and it errors on the second line:

    RTE-9 Sub-Script out of range

    Fix that:

    ActiveDocument.CustomXMLParts.Add "<supplier xmlns='http://invoice'/>"
    Set cxp1 = ActiveDocument.CustomXMLParts("http://invoice")

    and it errors on the third line RTE 438 object doesn't support this property or method.

    At this point the person looking to get help is only getting frustrated.

    Fix that

    Dim cxp1 As CustomXMLPart
    Dim cxn As CustomXMLNode
    ActiveDocument.CustomXMLParts.Add "<supplier xmlns='http://invoice'><company supplierID='1'>Acme Hardware</company></supplier>"
    Set cxp1 = ActiveDocument.CustomXMLParts("http://invoice")
    Set cxn = cxp1.SelectSingleNode("//*[@supplierID = 1]")

    and you finally have a working example.

    My point being when I first visited help for "SelectSingleNode" I didn't know how to fix any of the errors and was only frustrated.

    Then help if full of non-functional examples like the one above.  It would be so much better if the help contained functional examples.

     

    Thanks.

     


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    5 years later and the explicit examples of faulty documentation that MS had requested and were subsequently provided are still 'untouched'. Suffice it to say that the follow-on negativity regarding 'what's the point of ever providing MS any feedback' was indeed Spot-On. Sigh...

    MS: "Here's some broken crap for you to figure out how to use..."

    Developers: "What about this or that aspect?'

    MS: "Zzzzzzzzzzzzzzzzzzzzzz"

    
    Thursday, October 20, 2016 9:02 PM