CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Posts
    12

    Question Using XML to store and retrieve data in a smart device application.

    Hello, i am trying to develop a small pocket pc smart device application in vb.net, i want to read some simple data into my application from another location.
    Somenone i know directed me to this page at msdn:
    http://msdn.microsoft.com/library/d...tcpctfrmwrk.asp

    but i must admit i think the is far more advanced than i require(??) i have not found it very useful as it is it far beyond what i have ever dealt with before. I simply want to read-in from an external file (of some type) called products, a few records, say 10, each with 10 fields and then place these in an array. e.g.
    PRODUCTS

    Tea
    75 cents
    168 boxes

    Coffee
    89 cents
    134 boxes

    Bread
    45 cents
    50 loaves

    Then in vb.net this would become PRODUCTS{tea, 75 cents, 168 boxes etc etc}

    does anyone know how xml could be simply applied to achieve this??

  2. #2
    Join Date
    Oct 2004
    Posts
    21

    Re: Using XML to store and retrieve data in a smart device application.

    This might help, I got it from the VB.NET Cookbook...

    The XML document would look something like this -

    <?xml version = "1.0"?>
    <Order id="2003-04-12-4996">
    <Client id="CMPSO33UL">
    <Name>CompuStation</Name>
    </Client>
    <Items>
    <Item id="2003">
    <Name>Calculator</Name>
    <Price>24.99</Price>
    </Item>
    <Item id="4311">
    <Name>Printer</Name>
    <Price>400.00</Price>
    </Item>
    </Items>
    </Order>

    Then, you would create a generic procedure for processing the node, and call it recursively -

    Code:
    Public Module XmlOutputTest
    
    Public Sub Main()
      'Load document
      Dim Doc As New XmlDocument
      Doc.Load("orders.xml")
      'Start node walk at the root
      DisplayNode(Doc.DocumentElement, 0)
      Console.ReadLine()
    End Sub
    
    Private Sub DisplayNode(ByVal node As XmlNode, ByVal depth As Integer)
      'Define indent level
      Dim Indent As New String(" "c, depth * 4)
    
      'Display node type
      Console.WriteLine(Indent & node.NodeType.ToString() & ": <" & node.Name & ">")
    
      'Display node content
      If node.Value <> String.Empty Then
        Console.WriteLine(Indent & "Value: " & node.Value)
      End If
    
      'Display nested nodes
      Dim Child As XmlNode
      For Each Child In node.ChildNodes
        DisplayNode(Child, depth + 1)
      Next
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured