Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8402263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:00:42+00:00 2026-06-09T22:00:42+00:00

I’d like to use XML Deserializer to parse the following XML structure <function_type start_key=02

  • 0

I’d like to use XML Deserializer to parse the following XML structure

  <function_type start_key="02" key_index_reverse="true" key_index="1" key_index_length="1" key="03" name ="N/A" id="N/A" transmission="rx">
    <data_type size="1">STX</data_type>
    <data_type size="1">Respond</data_type>
    <data_type size="2" unbounded="true" end="03">Function Code
      <convert>30,IND RESPOND</convert>
      <convert>31,GRP RESPOND</convert>
      <convert>32,PATTERN RESPOND</convert>
      <convert>33,F PATTERN RESPOND</convert>
      <convert>34,DIMMING RESPOND</convert>
      <data_type size="2" address="true">ADDRESS</data_type>
      <data_type size="4" decimal="true">CIRCUIT NUMBER</data_type>
      <data_type size="1">Value
        <convert>30,OFF</convert>
        <convert>31,ON</convert>
      </data_type>
    </data_type>

Into something like this that I can use in my application:

[XmlRoot("function_type")]
public class FunctionType
{
    [XmlAttribute("name")]
    public string Name { get; set; }

    [XmlAttribute("id")]
    public string ID { get; set; }

    [XmlAttribute("size_total")]
    public int TotalSize { get; set; }

    [XmlAttribute("key")]
    public string Key { get; set; }

    [XmlAttribute("transmission")]
    public string Transmission { get; set; }

    [XmlElement("data_type")]
    public List<AttributeType> Types { get; set; }

    [XmlAttribute("key_index")]
    public int KeyIndex { get; set; }

    [XmlAttribute("key_index_length")]
    public int KeyIndexLength { get; set; }

    [XmlAttribute("key_index_reverse")]
    public bool KeyIndexReverse { get; set; }

    public FunctionType()
    {
        Types = new List<AttributeType>();
    }
}

public class AttributeType
{
    [XmlAttribute("size")]
    public int Size { get; set; }

    [XmlAttribute("decimal")]
    public bool IsDecimal { get; set; }

    [XmlAttribute("start_key")]
    public string StartKey { get; set; }

    [XmlAttribute("key")]
    public string Key { get; set; }

    [XmlAttribute("address")]
    public bool IsAddress { get; set; }

    [XmlAttribute("unbounded")]
    public bool IsUnbounded { get; set; }

    [XmlAttribute("end_key")]
    public int EndKey{ get; set; }

    [XmlElement("convert")]
    public List<ConversionType> Converts { get; set; }

    [XmlText]
    public string Value { get; set; }
}

public class ConversionType
{
    [XmlText]
    public string ConvertValue { get; set; }
}
public static class StringExtensions
{
    public static T XmlDeserialize<T>(this string s)
    {
        var locker = new object();
        var stringReader = new StringReader(s);
        var reader = new XmlTextReader(stringReader);
        try
        {
            var xmlSerializer = new XmlSerializer(typeof(T));
            lock (locker)
            {
                var item = (T)xmlSerializer.Deserialize(reader);
                reader.Close();
                return item;
            }
        }
        catch
        {
            return default(T);
        }
        finally
        {
            reader.Close();
        }
    }
}

The problem I’m encountering is I have some inception stuff going on in the XML file that I have to deserialize a data_type tag that is inside a data_type tag.

How would one circumvent this issue instead of having to define another class that is differently named?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:00:44+00:00Added an answer on June 9, 2026 at 10:00 pm

    Add property to your AttributeType class

    [XmlElement("data_type")]
    public List<AttributeType> Types { get; set; }
    

    result

    public class AttributeType
    {
        [XmlAttribute("size")]
        public int Size { get; set; }
    
        [XmlAttribute("decimal")]
        public bool IsDecimal { get; set; }
    
        [XmlAttribute("start_key")]
        public string StartKey { get; set; }
    
        [XmlAttribute("key")]
        public string Key { get; set; }
    
        [XmlAttribute("address")]
        public bool IsAddress { get; set; }
    
        [XmlAttribute("unbounded")]
        public bool IsUnbounded { get; set; }
    
        [XmlAttribute("end_key")]
        public int EndKey { get; set; }
    
        [XmlElement("convert")]
        public List<ConversionType> Converts { get; set; }
    
        [XmlElement("data_type")]
        public List<AttributeType> Types { get; set; }
    
        [XmlText]
        public string Value { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.