Deserializing hefty XML doc into c# objects

32 views Asked by At

I've been banging my head against the wall looking for how to deserialize this sample doc

<?xml version="1.0" encoding="UTF-8"?>
<MESSAGE MISMOReferenceModelIdentifier="3.4.032420160128" xmlns:blend="http://www.blendlabs.com" xmlns:ULAD="http://www.datamodelextension.org/Schema/ULAD" xmlns="http://www.mismo.org/residential/2009/schemas" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" targetNamespace="http://www.mismo.org/residential/2009/schemas">
  <ABOUT_VERSIONS>
    <ABOUT_VERSION>
      <AboutVersionIdentifier>3.4.0</AboutVersionIdentifier>
      <CreatedDatetime>2021-12-22T18:25:30Z</CreatedDatetime>
    </ABOUT_VERSION>
  </ABOUT_VERSIONS>
  <DEAL_SETS>
    <DEAL_SET>
      <DEALS>
        <DEAL>
          <ASSETS>
            <ASSET SequenceNumber="1" xlink:label="ASSET_1">
              <ASSET_DETAIL>
                <AssetAccountIdentifier>0000</AssetAccountIdentifier>
                <AssetCashOrMarketValueAmount>110.00</AssetCashOrMarketValueAmount>
                <AssetType>CheckingAccount</AssetType>
              </ASSET_DETAIL>
              <ASSET_HOLDER>
                <ADDRESS>
                  <AddressLineText>100 N Tryon St, Ste 170</AddressLineText>
                  <CityName>Charlotte</CityName>
                  <CountryCode>US</CountryCode>
                  <CountryName>USA</CountryName>
                  <PostalCode>28202</PostalCode>
                  <StateCode>NC</StateCode>
                </ADDRESS>
                <NAME>
                  <FullName>Bank of America</FullName>
                </NAME>
              </ASSET_HOLDER>
              <EXTENSION>
                <OTHER>.....

using this code

    XmlSerializer serializer = new XmlSerializer(typeof(MESSAGE));

    // Deserialize the XML document
    MESSAGE msgData;
    using (FileStream fs = new FileStream("filePath", FileMode.Open))
    {
        msgData = (MESSAGE)serializer.Deserialize(fs);
    }

My classes were generated using xsd.exe from our schema and it is too big to post here easily. MESSAGE class does not contain an [XMLArray] or [XMLArrayItem] if that helps.

I put breakpoints just after the .Deserialize... line and it returns only element names and null for all datapoints within. Am I doing something stupidly wrong here?

Should I instantiating a List to save the data to once it's fixed so we can use the objects down the road? Thanks

0

There are 0 answers