Hi Folks,
I am trying to generate an XML file with element as "name" in it. file is sucessfully generated from database table as shown in code below, but i dont understand how to add name element same as node name.
my purpose of doin this is: I have 2 columns in table and when i bind it to combo box it shows both the columns in dropdown. then i tried by adding name="element" in the node it worked. is there any way i can add thins on the fly while generation of xml files.
(or is there any way of querying i can fetch test_name by using where condition. i am really confused with this query thing and scope of it. can any one help.)
Dim tstNmSql As String = "SELECT PRODUCT_NAME, TEST_NAME FROM REL_TEST_NAMES" Dim tstNmAdapter As SqlDataAdapter = New SqlDataAdapter(tstNmSql, myConnection) tstNmAdapter.Fill(ds, "XML_TEST_NAME") ds.WriteXml(xml_tstNmList, XmlWriteMode.IgnoreSchema) tstNmAdapter.Dispose() ds.Clear()
this code generates xml file like code below. but, i want to do <PRODUCT_NAME name='PRODUCT_NAME'>ALx</PRODUCT_NAME>
< xml version="1.0" standalone="yes" > <NewDataSet> <XML_TEST_NAME> <PRODUCT_NAME>ALx</PRODUCT_NAME> <TEST_NAME>NBQ SEx</TEST_NAME> </XML_TEST_NAME> <XML_TEST_NAME> <PRODUCT_NAME>ALxxA</PRODUCT_NAME> <TEST_NAME>NBQ SExxxA</TEST_NAME> </XML_TEST_NAME> </NewDataSet>
Sub Xpath()
'XML document path
Dim myXPathDocument As XPathDocument = New XPathDocument("d:\xmlTestFilesFromJag_Code_Project\xml_tstNmList.xml")
'XML Path Navigator
Dim myXPathNavigator As XPathNavigator = myXPathDocument.CreateNavigator()
'XML Node query
'Dim myXPathNodeIterator As XPathNodeIterator = myXPathNavigator.Select("/NewDataSet/XML_TEST_NAME[PRODUCT_NAME='SORCERY']") '<--- populates with both the columns
Dim myXPathNodeIterator As
While (myXPathNodeIterator.MoveNext())
If myXPathNodeIterator.Current.Name = "PRODUCT_NAME" Then
Me.Test_Cmb.Items.Add(myXPathNodeIterator.Current.Value)
End If
End While
End Sub
any help would be really appreciated.
Regards
.NET Development11
|