Solved

XML File

Posted on 2011-03-24
4
353 Views
Last Modified: 2012-05-11
I’m new to vb.NET and I’m creating a project with 5 tables, with the largest table having about 25 records, I would like to use XML.

I need some sample code showing how to
1.  Create the XML database
2.  Create the file structure
3.  Do Inserts
4.  Do Updates
5.  Do Deletes
6.  Do Searches

If anyone has any sample code I would appreciate it.
0
Comment
Question by:PhilChapmanJr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 35211093
0
 
LVL 2

Author Comment

by:PhilChapmanJr
ID: 35212511
The http://vb.net-informations.com/xml/vb.net-xml-tutorial.htm
has good examples of Createing and searching as XML File

Private Sub cmdCreateXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCreateXML.Click
        Dim writer As New XmlTextWriter("c:\product.xml", System.Text.Encoding.UTF8)

        writer.WriteStartDocument(True)
        writer.Formatting = Formatting.Indented
        writer.Indentation = 2
        writer.WriteStartElement("Table")
        createNode(1, "Product 1", "1000", writer)
        createNode(2, "Product 2", "2000", writer)
        createNode(3, "Product 3", "3000", writer)
        createNode(4, "Product 4", "4000", writer)
        writer.WriteEndElement()
        writer.WriteEndDocument()
        writer.Close()
    End Sub

Private Sub createNode(ByVal pID As String, ByVal pName As String, ByVal pPrice As String, ByVal writer As XmlTextWriter)

        writer.WriteStartElement("Product")
        writer.WriteStartElement("Product_id")
        writer.WriteString(pID)
        writer.WriteEndElement()
        writer.WriteStartElement("Product_name")
        writer.WriteString(pName)
        writer.WriteEndElement()
        writer.WriteStartElement("Product_price")
        writer.WriteString(pPrice)
        writer.WriteEndElement()
        writer.WriteEndElement()

    End Sub

Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click

        Dim xmlFile As XmlReader

        xmlFile = XmlReader.Create("c:\product.xml", New XmlReaderSettings())
        Dim ds As New DataSet
        Dim dv As DataView
        ds.ReadXml(xmlFile)

        dv = New DataView(ds.Tables(0))
        dv.Sort = "Product_Name"
        Dim index As Integer = dv.Find("Product 2")

        If index = -1 Then
            MsgBox("Item Not Found")
        Else
            MsgBox(dv(index)("Product_Name").ToString() & "  " & dv(index)("Product_Price").ToString())
        End If

    End Sub

But how would you
Insert a new record, Delete a Record and Update a Record


Example:
How would you insert 5, "Product 5", "5000"
and delete Item 3
and Update Item  2 from 2000 to 2050
0
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 35212542
Creation code looks good, for searching use XPath. something like:
' Load the XmlDocument.
Dim xd As New XmlDocument()
xd.Load("C:\XmlTest.xml")
' Find the node where the Person's attribute ID is 1 using its XPath.
Dim nod As XmlNode = xd.SelectSingleNode("/Table/Product[@Product_Name='Product 2']")

the lilnk below contains a sample on how to search as well.

Note: Sorry forgot to add this link: (sample of add, delete, update under "Add to an XML File", "Delete an XML Node", "Edit an XML File")
http://www.vbforums.com/archive/index.php/t-478692.html
0
 
LVL 2

Author Closing Comment

by:PhilChapmanJr
ID: 35212640
Thanks again for the assistance
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question