views:

137

answers:

1

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?

A: 

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)

Tony

related questions