将架构添加到CustomXMLPart [英] Add schema to CustomXMLPart

查看:95
本文介绍了将架构添加到CustomXMLPart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已编辑6/20/2011

Edited 6/20/2011

我已在我的文档中创建并添加了CustomXMLPart。 我还创建了一个.xsd模式文件,我想用它来验证XML。 

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. 

使用  VBA 用户可以访问customXMLPart中的数据或更改现有数据数据:



例如,以下代码允许用户修改员工的日期:

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()

'为特定员工设置节点数据(例如,雇用)(例如员工ID 003)

Dim pData As String

如果Len(选择。文字)> 1然后

  pData = Selection.Text

否则为
  pData = InputBox("输入节点数据","NODE DATE INPUT")

结束如果是
如果不是SetXMLStringData(PERSONNEL,"003","hiredate" ;,pData)= True然后

  MsgBox"未找到符合此条件的数据节点",vbOKOnly

结束如果

结束次要



雇用者应为有效日期。 实际上,用户可以选择任何文本或在输入框中输入任何值,并将该值写入节点。 例如,如果用户进入"上周",在输入框中运行代码,相应的
节点值更改为:



< employee id =" 003">

        < firstname> Mary< / firstname>

        < lastname> Miller< / lastname>

        < hiredate>上周< / hiredate>

    < / 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.)

我尝试将架构添加到customXMLPart架构集合中:



Sub AddSchema()

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

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."

我使用Developer> XML> Schema> Add Schema手动将模式添加到文档XML模式集合中&NBSP;我还确认架构确实验证了文档中的hiredate节点(我手动将hiredate节点添加到文档文本
,其中包含无效数据,并且带有下划线)。

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).

我手动确认(或者至少认为我确认了)即使架构位于文档架构集合中,它也不会被CustomXMLPart使用:

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

 设置cxp1 = .CustomXMLParts(4)

 设置ValErrors = cxp1.Errors

结束于
如果ValErrors.Count> 0然后

  对于ValErrors中的每个ValError

      Debug.Print("错误名称:&& ValError.Name&"错误说明:&& ValError.Text)

  下一个

结束如果

结束子

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

所以这里就是 看台。  1)我的文档中加载了一个customXMLPart,其中包含一个带有无效数据的节点(hiredate)(如果根据模式进行检查)。  2)当我尝试将模式添加到CustomXMLPart模式集合时,我得到
一个错误,表示无法重新加载模式,因为模式集合当前正在使用。 3)将模式添加到文档集合中似乎不会对CustomXMLPart XML产生任何影响。 4)
上的整个Office / Word帮助这个和其他CustomXMLPart方法和属性都有一半不能使用的半实例。

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.

任何人都可以告诉我如何添加一个到CustomXMLPart的模式,因此任何尝试对XML进行无效(模式违规)更改都会被检测和阻止,或者b)在更改后检测XML中的无效输入。

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.

指向使用CustomXMLSchemaCollection和CustomXMLValidationErrors的工作示例的指针将是盛大的。



谢谢。

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

Thanks.

 

推荐答案

Hi Gray,

Hi Grey,

我们正在研究您的问题。响应可能会有一些延迟。感谢您的耐心等待。

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

最诚挚的问候,


这篇关于将架构添加到CustomXMLPart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆