Click here to Skip to main content
15,850,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using xsd.exe tool to create XML Schema (XSD) for the following file
XML
<time>
<Hours_List>
    <Number>12</Number>
    <Name>08:00</Name>
    <Name>09:00</Name>
    <Name>10:00</Name>
    <Name>11:00</Name>
    <Name>12:00</Name>
    <Name>13:00</Name>
    <Name>14:00</Name>
    <Name>15:00</Name>
    <Name>16:00</Name>
    <Name>17:00</Name>
    <Name>18:00</Name>
    <Name>19:00</Name>
</Hours_List>

<Days_List>
    <Number>5</Number>
    <Name>Monday</Name>
    <Name>Tuesday</Name>
    <Name>Wednesday</Name>
    <Name>Thursday</Name>
    <Name>Friday</Name>
</Days_List>
</time>

by xsd.exe and \dataset option , or drag xsd file directly in solution explorer and write this code
C#
Time t = new Time();
 t.ReadXml(@"E:\Time_check.xml");


error meassage appear when using dataset for this xsd schema
The same table 'Name' cannot be the child table in two nested relations.

how can i solve this problem ?
I want to handle this schema without
change "name" element to "hourName" and "dayName" for example or change "number" element to attribute,since another program (not open source) take generated XML file to deal with.
Posted
Updated 20-Oct-17 0:39am
v2

1 solution

You could rename the nodes with XSLT and then read it in, and then rename them back when writing the output.

XML
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:output method="xml" indent="yes"/>

  <xsl:template match="*">
    <xsl:param name="parentElm">
      <xsl:value-of select="name(..)" />
    </xsl:param>
    <xsl:choose>
      <xsl:when test="local-name() = 'Name'">
        <xsl:element name="{concat('Name',$parentElm)}">
          <xsl:apply-templates select="@* | node()" />
        </xsl:element>
      </xsl:when>
      <xsl:otherwise>
        <xsl:element name="{local-name()}">
          <xsl:copy-of select="@*" />
          <xsl:apply-templates select="@* | node()" />
        </xsl:element>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>


I took the XSLT example from here: http://stackoverflow.com/questions/397426/xsd-class-generation-nested-tables-problem[^]
 
Share this answer
 
Comments
ibrahim_ragab 20-Mar-13 10:45am    
thanks very much
but how can I use xslt file in C# code?
and how can I generate it for large xml that contain hundred of conversions(edit in visual studio text editor will be hard)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900