views:

48

answers:

2

I auto generated an xsd file from the below xml and used xsd2code to get a c# class. The problem is the entire xml doesn't deserialize.

Here is how I'm attempting to deserialize:

    static void Main(string[] args)
    {
        using (TextReader textReader = new StreamReader("config.xml"))
        {
           // string temp = textReader.ReadToEnd();
            XmlSerializer deserializer = new XmlSerializer(typeof(project));
            project p = (project)deserializer.Deserialize(textReader);
        }
    }

here is the actual XML:

<?xml version='1.0' encoding='UTF-8'?>
<project>
  <scm class="hudson.scm.SubversionSCM">
    <locations>
      <hudson.scm.SubversionSCM_-ModuleLocation>
        <remote>https://svn.xxx.com/test/Validation/CPS DRTest DLL/trunk</remote>
      </hudson.scm.SubversionSCM_-ModuleLocation>
    </locations>
    <useUpdate>false</useUpdate>
    <browser class="hudson.scm.browsers.FishEyeSVN">
      <url>http://fisheye.xxxx.net/browse/Test/&lt;/url&gt;
      <rootModule>Test</rootModule>
    </browser>
    <excludedCommitMessages></excludedCommitMessages>
  </scm>
  <openf>Hello there</openf>
  <buildWrappers/>
</project>

When I run the above, the locations node remains null.

Here is the xsd that I'm using:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="project">
    <xs:complexType>
      <xs:all>
        <xs:element name="openf" type="xs:string" minOccurs="0" />
        <xs:element name="buildWrappers" type="xs:string" minOccurs="0" />
        <xs:element name="scm" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="useUpdate" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
              <xs:element name="excludedCommitMessages" type="xs:string" minOccurs="0" msdata:Ordinal="2" />
              <xs:element name="locations" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="hudson.scm.SubversionSCM_-ModuleLocation" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="remote" type="xs:string" minOccurs="0" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="browser" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="url" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
                    <xs:element name="rootModule" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
                  </xs:sequence>
                  <xs:attribute name="class" type="xs:string" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="class" type="xs:string" />
          </xs:complexType>
        </xs:element>
      </xs:all>
    </xs:complexType>
  </xs:element>
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="project" />
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>
A: 

According to this page '.' is not a valid XML tag name character, so you need to rename <hudson.scm.SubversionSCM_-ModuleLocation> to something without the dots.

Chuck Wilbur
This shouldn't be the problem. Dots are fine within XML names. They are included in production [4a] in both the XML 1.0 and XML 1.1 recommendation. What you cannot do is use a dot to start a name.
Andrew Walker
A: 

Figured it out. When using xsd2code I had select options to target the 3.5 framework and include the xml attributes. It now deserializes as expected. Not sure which one did it, but works now.

Andy