|
-
April 5th, 2012, 08:20 AM
#1
Adding New Node to Xml document
I'v been reading and reading on this subject an from what iv got so far, you add a Node and then append elements to that new node which then appends to the parent node. My current schema for my xml document is as follows:
The Xml Structure is
<Queries>
<Query>
<Name> Query Name </Name>
<Action></Action>
<Text>
Query does something here
</Text>
<Parameters>
<Parameter>
<Name> Param Name </name>
etc...
</Parameter>
</Parameters>
</Query>
</Queries>
I basically am getting the above values from input via textbox input. What i want is to add a <Query> node with the values inputted from a textbox. Im just unsure of how to create this structure in vb.net... This is the code i have so far.
Public Sub AppendNewQuery(ByVal doc As XmlDocument)
Dim newQueryNode As XmlNode = QueryList.XMLDoc.CreateNode(XmlNodeType.Element, "Query", Nothing)
'newQueryNode.InnerText = "Text from Query Name TextBox"
Dim QueryName As XmlNode = QueryList.XMLDoc.CreateElement("Name")
QueryName.InnerText = NewQueryNameTXT.Text
Dim QueryAction As XmlNode = QueryList.XMLDoc.CreateElement("Action")
QueryAction.InnerText = NewQueryActionTXT.Text
Dim QueryText As XmlNode = QueryList.XMLDoc.CreateElement("Text")
QueryText.InnerText = QueryEditor.Text
newQueryNode.AppendChild(QueryName)
newQueryNode.AppendChild(QueryAction)
newQueryNode.AppendChild(QueryText)
QueryList.XMLDoc.DocumentElement.AppendChild(newQueryNode)
QueryList.XMLDoc.Save(My.Settings.QueryFile)
End Sub
-
April 9th, 2012, 12:47 PM
#2
Re: Adding New Node to Xml document
I have also resolved this myself, code i used is below...of course there is more to it but this is the heart of how it works.
Dim paramEleName As XmlNode = QueryList.XMLDoc.CreateElement("Name")
Dim paramEleType As XmlNode = QueryList.XMLDoc.CreateElement("DataType")
Dim paramEleDisplay As XmlNode = QueryList.XMLDoc.CreateElement("DisplayName")
Dim parameter As ParameterBL = r.DataBoundItem
paramEleName.InnerText = parameter.Name.ToString
paramEleType.InnerText = parameter.DataType.ToString
paramEleDisplay.InnerText = parameter.DisplayName.ToString
parameterNode.AppendChild(paramEleName)
parameterNode.AppendChild(paramEleType)
parameterNode.AppendChild(paramEleDisplay)
ParametersRootNode.AppendChild(parameterNode)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|