473,461 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need help with XML format in vb.net

I have the following code:

Dim ds As New Data.DataSet("inventory")
Dim dt As New Data.DataTable("desk")

'dt.TableName = "desk"
With dt
.Columns.Add("item")
.Columns.Add("qty")
End With
dt.Rows.Add(New Object() {"Paper Clip", 100})
dt.Rows.Add(New Object() {"Stapler", 1})
dt.Rows.Add(New Object() {"Tape", 2})
ds.Tables.Add(dt)
At this point, ds.GetXml will produces the following XML:

<inventory>
<desk>
<item>Paper Clip</item>
<qty>100</qty>
</desk>
<desk>
<item>Stapler</item>
<qty>1</qty>
</desk>
<desk>
<item>Tape</item>
<qty>2</qty>
</desk>
</inventory>

What is the best way with VB.net to make the XML look like this
instead:

<inventory>
<desk>
<item qty='100'>Paper Clip</item>
<item qty='1'>Stapler</item>
<item qty='2'>Tape</item>
</desk>
</inventory>

Aug 21 '08 #1
3 1313

1. Don't use a dataset. Its element based. Use XmlDocument instead (or
XmlWriter or other)
2. Transform it.
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!148.entry

<ab*********@gmail.comwrote in message
news:f6**********************************@a70g2000 hsh.googlegroups.com...
>I have the following code:

Dim ds As New Data.DataSet("inventory")
Dim dt As New Data.DataTable("desk")

'dt.TableName = "desk"
With dt
.Columns.Add("item")
.Columns.Add("qty")
End With
dt.Rows.Add(New Object() {"Paper Clip", 100})
dt.Rows.Add(New Object() {"Stapler", 1})
dt.Rows.Add(New Object() {"Tape", 2})
ds.Tables.Add(dt)
At this point, ds.GetXml will produces the following XML:

<inventory>
<desk>
<item>Paper Clip</item>
<qty>100</qty>
</desk>
<desk>
<item>Stapler</item>
<qty>1</qty>
</desk>
<desk>
<item>Tape</item>
<qty>2</qty>
</desk>
</inventory>

What is the best way with VB.net to make the XML look like this
instead:

<inventory>
<desk>
<item qty='100'>Paper Clip</item>
<item qty='1'>Stapler</item>
<item qty='2'>Tape</item>
</desk>
</inventory>

Aug 21 '08 #2
On Aug 21, 3:33*pm, "sloan" <sl...@ipass.netwrote:
1. *Don't use a dataset. *Its element based. *Use XmlDocument instead (or
XmlWriter or other)
2. *Transform it.http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!148.entry

<abaker.j...@gmail.comwrote in message

news:f6**********************************@a70g2000 hsh.googlegroups.com...
I have the following code:
* * * *DimdsAsNewData.DataSet("inventory")
* * * *Dimdt AsNewData.DataTable("desk")
* * * *'dt.TableName = "desk"
* * * *With dt
* * * * * *.Columns.Add("item")
* * * * * *.Columns.Add("qty")
* * * *End With
* * * *dt.Rows.Add(NewObject() {"Paper Clip", 100})
* * * *dt.Rows.Add(NewObject() {"Stapler", 1})
* * * *dt.Rows.Add(NewObject() {"Tape", 2})
* * * *ds.Tables.Add(dt)
At this point,ds.GetXml will produces the following XML:
<inventory>
*<desk>
* *<item>Paper Clip</item>
* *<qty>100</qty>
*</desk>
*<desk>
* *<item>Stapler</item>
* *<qty>1</qty>
*</desk>
*<desk>
* *<item>Tape</item>
* *<qty>2</qty>
*</desk>
</inventory>
What is the best way with VB.net to make the XML look like this
instead:
<inventory>
<desk>
*<item qty='100'>Paper Clip</item>
*<item qty='1'>Stapler</item>
*<item qty='2'>Tape</item>
</desk>
</inventory>- Hide quoted text -

- Show quoted text -
Can someone give me an xslt file that I can use to convert the first
example to the second example?
Aug 28 '08 #3
On Aug 28, 10:28*am, abaker.j...@gmail.com wrote:
On Aug 21, 3:33*pm, "sloan" <sl...@ipass.netwrote:


1. *Don't use a dataset. *Its element based. *Use XmlDocument instead (or
XmlWriter or other)
2. *Transform it.http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!148.entry
<abaker.j...@gmail.comwrote in message
news:f6**********************************@a70g2000 hsh.googlegroups.com....
>I have the following code:
* * * *DimdsAsNewData.DataSet("inventory")
* * * *Dimdt AsNewData.DataTable("desk")
* * * *'dt.TableName = "desk"
* * * *With dt
* * * * * *.Columns.Add("item")
* * * * * *.Columns.Add("qty")
* * * *End With
* * * *dt.Rows.Add(NewObject() {"Paper Clip", 100})
* * * *dt.Rows.Add(NewObject() {"Stapler", 1})
* * * *dt.Rows.Add(NewObject() {"Tape", 2})
* * * *ds.Tables.Add(dt)
At this point,ds.GetXml will produces the followingXML:
<inventory>
*<desk>
* *<item>Paper Clip</item>
* *<qty>100</qty>
*</desk>
*<desk>
* *<item>Stapler</item>
* *<qty>1</qty>
*</desk>
*<desk>
* *<item>Tape</item>
* *<qty>2</qty>
*</desk>
</inventory>
What is the best way withVB.netto make theXMLlook like this
instead:
<inventory>
<desk>
*<item qty='100'>Paper Clip</item>
*<item qty='1'>Stapler</item>
*<item qty='2'>Tape</item>
</desk>
</inventory>- Hide quoted text -
- Show quoted text -

Can someone give me an xslt file that I can use to convert the first
example to the second example?- Hide quoted text -

- Show quoted text -
I got the answer in another thread:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="inventory">
<xsl:copy>
<desk>
<xsl:apply-templates select="desk/item"/>
</desk>
</xsl:copy>
</xsl:template>
<xsl:template match="item">
<item qty="{following-sibling::qty}">
<xsl:apply-templates/>
</item>
</xsl:template>
</xsl:stylesheet>
Aug 28 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: lawrence | last post by:
Can someone please tell me where I can get some open source code for resizing images? I know such code has been written a million times and I don't feel like doing it again from scratch.
3
by: David L | last post by:
Hi, I am wondering that whether the fact that as more tools/environments/products support XML, then the need for knowing XML itself gets less important. I am comparing xml to assembler. IT...
4
by: Brian Coy | last post by:
I have a database that records a part no, a scrap reason, the cost of scrapping that item, and the date. I need to porduce a report that will show up to a weeks worth of data at a time, but I need...
1
by: Glenn Profitt | last post by:
Hi, I am using a text box as the subject for an invoice email. The textbox works fine for listing individual fields from the tblOrders table as shown below: ="Hi, " & & " " & "Your order is...
5
by: Alicia | last post by:
Hello everyone based on the data, I created a union query which produces this. SELECT ,,, 0 As ClosedCount FROM UNION SELECT ,, 0 AS OpenedCount, FROM ORDER BY , ;
4
by: Phil | last post by:
k, here is my issue.. I have BLOB data in SQL that needs to be grabbed and made into a TIF file and placed on the client (could be in temp internet dir). The reason we need it in TIF format is...
8
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to...
1
by: CptDondo | last post by:
I've been struggling with this concept for a while, and I'm getting a bit burned out... I've got a piece of equipment that has data that I need to get. The data is stored in "bytes" for lack...
2
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.