Binding XML with attribute to datagrid.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Dole

    #1

    Binding XML with attribute to datagrid.

    Why is it that when I want to use an attribute like for instance:
    .WriteAttribute String("WaiterI d", "14")
    and later on (in another application) want to bind the xml to a
    datagrid with readxml I'm not getting any records (just one row with
    14 in it..)
    If I ommit the attribute it works just fine?

    What am I doing wrong here, have to admit I'm more or less discovering
    xml..

    Thanks in advance,

    Mike



    [Code snippet which writes the XML (Compact Framework)]

    pXTWWriter = New XmlTextWriter(i FileName,
    System.Text.Enc oding.Default)

    'WRITE THE ROOT TAG
    .WriteStartElem ent("Table")
    .WriteAttribute String("WaiterI d", "14")

    'ADD THE DRINKS FIRST
    .WriteStartElem ent("Order")
    .WriteStartElem ent("Type")
    .WriteString("D rinks")
    .WriteEndElemen t()
    .WriteStartElem ent("Item")
    .WriteString("H eineken")
    .WriteEndElemen t()
    .WriteStartElem ent("Qty")
    .WriteString("2 ")
    .WriteEndElemen t()
    .WriteEndElemen t()
    Etc,etc


    [Code snippet which reads the XML (Desktop App.]


    Dim fs As New FileStream("ord er.xml", FileMode.Open)

    Dim xr As New XmlTextReader(f s)
    xr.WhitespaceHa ndling = WhitespaceHandl ing.None
    OrderDS = New DataSet
    OrderDS.ReadXml (xr)

    statusBar.Text = "Loaded XML data"
    xr.Close()
    fs.Close()
    Dim SourceTable As DataTable
    SourceTable = OrderDS.Tables( 0)
    dgOrder.DataSou rce = SourceTable
  • LeProgrammeur
    New Member
    • May 2006
    • 7

    #2
    Binding XML to DataGrid

    Originally posted by Mike Dole
    Why is it that when I want to use an attribute like for instance:
    .WriteAttribute String("WaiterI d", "14")
    and later on (in another application) want to bind the xml to a
    datagrid with readxml I'm not getting any records (just one row with
    14 in it..)
    If I ommit the attribute it works just fine?

    What am I doing wrong here, have to admit I'm more or less discovering
    xml..

    Thanks in advance,

    Mike



    [Code snippet which writes the XML (Compact Framework)]

    pXTWWriter = New XmlTextWriter(i FileName,
    System.Text.Enc oding.Default)

    'WRITE THE ROOT TAG
    .WriteStartElem ent("Table")
    .WriteAttribute String("WaiterI d", "14")

    'ADD THE DRINKS FIRST
    .WriteStartElem ent("Order")
    .WriteStartElem ent("Type")
    .WriteString("D rinks")
    .WriteEndElemen t()
    .WriteStartElem ent("Item")
    .WriteString("H eineken")
    .WriteEndElemen t()
    .WriteStartElem ent("Qty")
    .WriteString("2 ")
    .WriteEndElemen t()
    .WriteEndElemen t()
    Etc,etc


    [Code snippet which reads the XML (Desktop App.]


    Dim fs As New FileStream("ord er.xml", FileMode.Open)

    Dim xr As New XmlTextReader(f s)
    xr.WhitespaceHa ndling = WhitespaceHandl ing.None
    OrderDS = New DataSet
    OrderDS.ReadXml (xr)

    statusBar.Text = "Loaded XML data"
    xr.Close()
    fs.Close()
    Dim SourceTable As DataTable
    SourceTable = OrderDS.Tables( 0)
    dgOrder.DataSou rce = SourceTable
    Hi,
    I posted a tutorial about binding XML to DataGrid at www.KYNOU.com that might help you. Go to the link above and search for: Binding XML to DataGrid
    There is also a chat room there where I try to spend as more time as possible.
    :)

    Comment

    Working...