Need help with XML format in vb.net

A

abaker.junk

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>
 
A

abaker.junk

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:blush:utput 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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top