Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XML serialization
using xsd.exe tool to create XML Schema (XSD) for the following file
<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
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 19-Mar-13 13:45pm
Edited 19-Mar-13 13:55pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You could rename the nodes with XSLT and then read it in, and then rename them back when writing the output.
 
<?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[^]
  Permalink  
Comments
ibrahim_ragab at 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)

  Print Answers RSS
0 OriginalGriff 6,569
1 Sergey Alexandrovich Kryukov 6,168
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100