Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: New to Schemas

From: "tshad" <tshad@----------.--->
To: NULL
Date: 1/4/2008 4:34:00 PM


"Martin Honnen" <mahotrash@y...> wrote in message 
news:umrYot7SIHA.4752@T......
> tshad wrote:
>> I am trying to read an xml document into a dataSet and am unsure how to 
>> set it up.
>>
>> If I have a document such as:
>>
>> <?xml version="1.0"?>
>> <address country="Italy">
>>     <tag name="street" flag="5">One Microsoft Way</tag>
>>     <tag name="number">1</tag>
>>     <tag name="city">Redmond</tag>
>>     <tag name="state" unit="25">WA</tag>
>>     <tag name="zip">98052</tag>
>> </address>
>>
>> I want there to be one table: Address and each record would be the "tag" 
>> lines.  The line would have a name (such as "street" or "city") a value 
>> (such as ""One Microsoft Way") and a possible attribute or 2 (such as 
>> flag).
>>
>> I would want the table to be something like:
>>
>> street       5        One Microsoft Way
>> number              1
>> city                   Redmond
>> state            25 WA
>> zip                    98052
>

What does the following lines in your code do?  Do you need those lines if 
you are going to copy this to a dataset?

     <dataset>
       <xsl:apply-templates/>
     </dataset>

Thanks,

Tom

> One way to solve that is to use an XSLT stylesheet to transform the XML to 
> the format ReadXml expects. Here is an XSLT stylesheet that does that:
>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>   <xsl:output method="xml" indent="yes"/>
>   <xsl:template match="address">
>     <dataset>
>       <xsl:apply-templates/>
>     </dataset>
>   </xsl:template>
>   <xsl:template match="tag">
>     <address>
>       <name>
>         <xsl:value-of select="@name"/>
>       </name>
>       <flag>
>         <xsl:if test="not(@flag)">
>           <xsl:attribute name="xsi:nil">true</xsl:attribute>
>         </xsl:if>
>         <xsl:value-of select="@flag"/>
>       </flag>
>       <unit>
>         <xsl:if test="not(@unit)">
>           <xsl:attribute name="xsi:nil">true</xsl:attribute>
>         </xsl:if>
>         <xsl:value-of select="@unit"/>
>       </unit>
>       <value>
>         <xsl:value-of select="."/>
>       </value>
>     </address>
>   </xsl:template>
> </xsl:stylesheet>
>
> You can then apply the transformation with XslCompiledTransform as 
> follows:
>
>             XslCompiledTransform xsltProcessor = new 
> XslCompiledTransform();
>             xsltProcessor.Load(@"..\..\XSLTFile1.xslt");
>             DataSet ds = new DataSet();
>             using (MemoryStream memStream = new MemoryStream())
>             {
>                 xsltProcessor.Transform(@"..\..\XMLFile1.xml", null, 
> memStream);
>                 memStream.Position = 0;
>                 ds.ReadXml(memStream);
>             }
>
> That way you get one table with five rows:
>
> Table address:
> name    flag    unit    value
> street  5               One Microsoft Way
> number                  1
> city                    Redmond
> state           25      WA
> zip                     98052
>
>
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/ 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent