Anita C wrote:
I have an xml file with the structure:
<Customer Name="John">
<Order Number="0098"></Order>
</Customer>
How do I tranform the xml file to ensure that the Order Number is an
integer. The reason for this being that the xml file needs to be read into a
dataset and for the Order Table in the dataset I want to make the Number
column, the primary key as well as autoincremental. A code sample would be
great.
Well, as you are asking for transformation I assune you need XSLT solution?
Here is simple stylesheet that does the job:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Order/@Number">
<xsl:attribute name="Number">
<xsl:choose>
<!-- Check if it's a number -->
<xsl:when test="number()!=number()">
<!-- Not a number! What to do then? -->
<xsl:value-of select="-1"/>
</xsl:when>
<xsl:otherwise>
<!-- Ok, it's a number so let's round it to integer -->
<xsl:value-of select="round(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Otherwise it's more effective to use XmlTextReader.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel