XML write issue

Writing a XML file a certain way

Page 1 of 1

2 Replies - 1191 Views - Last Post: 06 January 2010 - 03:58 PM Rate Topic: -----

#1 RudyVB.net  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 03-May 08

XML write issue

Posted 04 January 2010 - 05:19 PM

Hello All!

So I have a issue I'm not sure how to handle. Here is what I'm trying to do. I'm writing a xml file based on the result of a table. Here is a sample of the table result.

395 XPort1 Xname1 YPort1 YName1 2009-12-28 1
396 XPort2 Xname2 YPort2 YName2 2009-12-28 1
397 XPort3 Xname3 YPort3 YName3 2009-12-28 1
398 XPort4 Xname4 YPort4 YName4 2009-12-28 1
399 XPort5 Xname5 YPort5 YName5 2009-12-28 1
400 XPort6 Xname6 YPort6 YName6 2009-12-28 1
401 XPort7 Xname7 YPort7 YName7 2009-12-28 2
402 XPort8 Xname8 YPort8 YName8 2009-12-28 2
403 XPort9 XName9 YPort9 Yaname9 2009-12-29 2

The last number is a seqNum. Every 6 rows that number will increment by 1.

This is the code that creates the XML file.
Private Sub WriteMontXML()

		
		Dim constr As New SqlConnection(DBConn)
		constr.Open()



		Dim dt As New DataTable("ConTbl")


		cmdUpd = New SqlCommand("SelCurConection2", constr)
		cmdUpd.CommandType = CommandType.StoredProcedure
		
		Dim dr As SqlDataReader = cmdUpd.ExecuteReader()

		dt.Load(dr)

		
		dt.WriteXml("c:\Monitor.xml", False)

	   
		dr.Close()

		dr = Nothing

		cmdUpd.Dispose()

		cmdUpd = Nothing

		constr.Close()

		constr = Nothing



	End Sub


This is the XML file result.

<?xml version="1.0" standalone="yes" ?>
- <DocumentElement>
- <ConTbl>
(4)<ConnID>395</ConnID>
(5)<X_Pt>XPort1</X_Pt>
(6)<X_Name>Xname1</X_Name>
(7)<Y_Pt>YPort1</Y_Pt>
(8)<Y_Name>YName1</Y_Name>
(9)<Conn_Date>2009-12-28T15:55:06.09-06:00</Conn_Date>
(10)<SeqNum>1</SeqNum>
</ConTbl>
- <ConTbl>
(13)<ConnID>396</ConnID>
(14)<X_Pt>XPort2</X_Pt>
(15)<X_Name>Xname2</X_Name>
(16)<Y_Pt>YPort2</Y_Pt>
(17)<Y_Name>YName2</Y_Name>
(18)<Conn_Date>2009-12-28T15:55:13.497-06:00</Conn_Date>
(19)<SeqNum>1</SeqNum>
</ConTbl>
- <ConTbl>
(22)<ConnID>397</ConnID>
(23)<X_Pt>XPort3</X_Pt>
(24)<X_Name>Xname3</X_Name>
(25)<Y_Pt>YPort3</Y_Pt>
(26)<Y_Name>YName3</Y_Name>
(27)<Conn_Date>2009-12-28T15:55:21.653-06:00</Conn_Date>
(28)<SeqNum>1</SeqNum>
</ConTbl>
- <ConTbl>
(31)<ConnID>398</ConnID>
(32)<X_Pt>XPort4</X_Pt>
(33)<X_Name>Xname4</X_Name>
(34)<Y_Pt>YPort4</Y_Pt>
(35)<Y_Name>YName4</Y_Name>
(36)<Conn_Date>2009-12-28T15:55:29.7-06:00</Conn_Date>
(37)<SeqNum>1</SeqNum>
</ConTbl>
- <ConTbl>
(40)<ConnID>399</ConnID>
(41)<X_Pt>XPort5</X_Pt>
(42)<X_Name>Xname5</X_Name>
(43)<Y_Pt>YPort5</Y_Pt>
(44)<Y_Name>YName5</Y_Name>
(45)<Conn_Date>2009-12-28T21:10:54.92-06:00</Conn_Date>
(46)<SeqNum>1</SeqNum>
</ConTbl>
- <ConTbl>
(49)<ConnID>400</ConnID>
(50)<X_Pt>XPort6</X_Pt>
(51)<X_Name>Xname6</X_Name>
(52)<Y_Pt>YPort6</Y_Pt>
(53)<Y_Name>YName6</Y_Name>
(54)<Conn_Date>2009-12-28T21:10:59.56-06:00</Conn_Date>
(55)<SeqNum>1</SeqNum>
</ConTbl>
- <ConTbl>
<ConnID>401</ConnID>
<X_Pt>XPort7</X_Pt>
<X_Name>Xname7</X_Name>
<Y_Pt>YPort7</Y_Pt>
<Y_Name>YName7</Y_Name>
<Conn_Date>2009-12-28T21:11:04.123-06:00</Conn_Date>
<SeqNum>2</SeqNum>
</ConTbl>
- <ConTbl>
<ConnID>402</ConnID>
<X_Pt>XPort8</X_Pt>
<X_Name>Xname8</X_Name>
<Y_Pt>YPort8</Y_Pt>
<Y_Name>YName8</Y_Name>
<Conn_Date>2009-12-28T21:11:08.543-06:00</Conn_Date>
<SeqNum>2</SeqNum>
</ConTbl>
- <ConTbl>
<ConnID>403</ConnID>
<X_Pt>XPort9</X_Pt>
<X_Name>XName9</X_Name>
<Y_Pt>YPort9</Y_Pt>
<Y_Name>Yaname9</Y_Name>
<Conn_Date>2009-12-29T00:28:14.373-06:00</Conn_Date>
<SeqNum>2</SeqNum>
</ConTbl>
</DocumentElement>

The numbers on the left side was added manually, so I can control where the elements are searched in the code. So disregard that.

So you notice the SeqNum changes to 2 after 6 records. I would like to create a new xml file after every SeqNum changes. Is there a way to do this?

Thanks!

Rudy

Is This A Good Question/Topic? 0
  • +

Replies To: XML write issue

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2256
  • View blog
  • Posts: 9,444
  • Joined: 29-May 08

Re: XML write issue

Posted 05 January 2010 - 02:05 AM

Have a look at use the xml literals that are available to you.
Its easier than you think.

See my blog post
Was This Post Helpful? 0
  • +
  • -

#3 RudyVB.net  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 03-May 08

Re: XML write issue

Posted 06 January 2010 - 03:58 PM

View PostAdamSpeight2008, on 5 Jan, 2010 - 01:05 AM, said:

Have a look at use the xml literals that are available to you.
Its easier than you think.

See my blog post


Thanks Adam!
It looks pretty straight forward. Thanks for the tip!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1