xquery and bind comboBox with XML file problem.  
Author Message
Jagjot Singh





PostPosted: XML and the .NET Framework, xquery and bind comboBox with XML file problem. Top

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  
 
 
Sergey Dubinets - MSFT





PostPosted: XML and the .NET Framework, xquery and bind comboBox with XML file problem. Top

Sorry, it's hard for me to understand your English. It may help if you reformulate your question.

You can generate different XML from DataSet. Instead of calling ds.WriteXml you can iterate it raw by raw and write values from the column to XmlWriter. This way you'd have full control over the generated output.

It would be better and simpler to fix XPath expression to serve your needs.

May be you need this query: myXPathNavigator.Select("/NewDataSet/XML_TEST_NAME[local-name(*) = 'SORCERY']")



 
 
Jagjot Singh





PostPosted: XML and the .NET Framework, xquery and bind comboBox with XML file problem. Top

Thanks alot,

sorry for my english. is there any online resource for XML, which you recommend for newbie. I dont have any idea how to create it step by step, "raw".

regards

jagjot