InfoPath 2007 - 通过托管代码添加属性和子节点
我正在将 InfoPath 2003 对象模型代码转换为 InfoPath 2007 托管代码,我想将属性和子节点添加到表单加载事件 (FormEvents_Loading) 上的表单部分。我想更新以下部分:
我要向 mstns:SpecificBook 节点和一些子节点添加一个属性。结果应该是:
我的 InfoPath 2003 对象模型代码
添加和设置属性值:
flag = TheXDocument.DOM.createAttribute("active") prereqsNode.attributes.setNamedItem(flagNode).text = "true"
newNode = doc.CreateNode(NodeTypeElemt, FromNamespacePrefix, "Book",FormNamespace)
specificBookAttrib = newNode.OwnerDocument.CreateAttribute("BookId")
specificBookIdAttrib.Value = “anybook”
newNode.Attributes.Append(specificBookIdAttrib)
SpecificBookNode.AppendChild(newNode)
任何人都可以帮我转换上面的行使用管理代码吗?
I’m converting my InfoPath 2003 Object Model Codes to InfoPath 2007 Managed Code, I want to add an attribute and childNodes to a section of form on form load event (FormEvents_Loading). I want to update the following section:
I was to add an attribute to mstns:SpecificBook node and a few child node. The result should be:
My InfoPath 2003 Object Model code
To Adding and Set attribute values:
flag = TheXDocument.DOM.createAttribute("active")
prereqsNode.attributes.setNamedItem(flagNode).text = "true"
newNode = doc.CreateNode(NodeTypeElemt, FromNamespacePrefix, "Book",FormNamespace)
specificBookAttrib = newNode.OwnerDocument.CreateAttribute("BookId")
specificBookIdAttrib.Value = “anybook”
newNode.Attributes.Append(specificBookIdAttrib)
SpecificBookNode.AppendChild(newNode)
Can anybody help me convert the line above use Manage code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为我可以创建一个新属性,因为 Sampledata.xml 有一个默认值,尽管我的 Template.xml 没有默认值;我无法设置该值,因为它是只读的。
prereqsNode = navigator.SelectSingleNode (“//mstns:SpecificBook”, Me.NamespaceManager)
*错误“属性重复”
prereqsNode.CreateAttribute("", "areLoaded", "", "true")
错误“只读”
prereqsNode.SetValue("true")*
我决定创建一个新的 XmlDocument:
创建一个新属性替换
整个 mstns:SpecificBook 节点
我还使用 XmlDocument 创建子节点,将节点转换为导航器,然后附加子节点。
Dim doc As XmlDocument = 新 XmlDocument
将 newNode 调暗为 XmlNode
Dim activeAttrib As XmlAttribute
activeAttrib = newNode.OwnerDocument.CreateAttribute("active")
activeAttrib.Value = True
newNode.Attributes.Append(activeAttrib)
SpecificBookNode.ReplaceSelf(newNode.OuterXml)
Since I could create a new attribute because the sampledata.xml had a default value although my Template.xml have none; I could not it set that value because it read only.
prereqsNode = navigator.SelectSingleNode (“//mstns:SpecificBook”, Me.NamespaceManager)
*Error “Duplicate attribute”
prereqsNode.CreateAttribute("", "areLoaded", "", "true")
Error “Read only”
prereqsNode.SetValue("true")*
I decided to create a new XmlDocument:
create a new attribute replace the
entire mstns:SpecificBook node
I also used XmlDocument to create the childNodes, convert the node to navigator and then append childNodes.
Dim doc As XmlDocument = New XmlDocument
Dim newNode As XmlNode
Dim activeAttrib As XmlAttribute
activeAttrib = newNode.OwnerDocument.CreateAttribute("active")
activeAttrib.Value = True
newNode.Attributes.Append(activeAttrib)
specificBookNode.ReplaceSelf(newNode.OuterXml)