0

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

  • I would *start* by reducing your problem to a really simple XML doc and really simple C# types. Personally I'm not a big fan of XmlSerializer anyway, but if you want to use it because your message structure is complex, it's worth getting it working on a very small example first. Once that's working, it should be easy to work out what you need to change about your real code. – Jon Skeet Apr 04 '23 at 07:49
  • What do you mean with "...null for all datapoints within"? – Good Night Nerd Pride Apr 04 '23 at 08:12
  • You are not getting an exception so what you have done so far is good. If you are not getting anything back than root tag on the xml isn't a message. If there was a namespace issue you would get an exception. – jdweng Apr 04 '23 at 09:01
  • We need to see a [mcve] to help you. If you can't post the classes for some reason, at least post a complete, well-formed XML sample + XSD sample + xsd.exe command line instructions we can use to generate the classes ourselves. Given that you have only posted a truncated and thus malformed XML sample, there's almost no chance we can solve your problem. See [ask]. – dbc Apr 04 '23 at 18:41
  • One thing I would suggest is that you verify that the XML is actually valid for your XSD schema. There are several online tools for this, you can google for them. When you do, be sure to check for unknown elements and attributes. If your XML is well-formed but not valid there's a chance that the serializer will return successfully but deserialize nothing because child elements don't have the expected names or namespaces. – dbc Apr 04 '23 at 18:45

0 Answers0