Extracting innertext and attribute using XmlSerializer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kishore

    Extracting innertext and attribute using XmlSerializer

    Hi
    I have a file similar to below


    <filter>
    <param id="xx">This is test</param>
    <param id="yy">This is another test </param>
    </filter>

    I created classes as below

    [XmlRoot("filter ")]
    public class Filter
    {
    [XmlElement("par am", typeof(Param))]
    Param [] params;
    }

    public class Param
    {
    [XmlAttribute("i d")]
    public string id;
    }


    All this is working fine. But I am not sure how to get the inner texts
    from the Param element. How can I get it through serialization?

    Please help.

    Thanks in advance.

  • Ollie Riches

    #2
    Re: Extracting innertext and attribute using XmlSerializer

    Xml serialisation is only going serialise the state of an object to xml it
    does not provide any mechanism to recurse the xml you will have to use an
    xml query tool for that.

    Also I believe you should be using the XmlArrayAttribu te on your array:

    [XmlRoot("filter ")]
    public class Filter
    {
    [XmlArray(Elemen tName = "Params")
    Param [] params;
    }

    [XmlElement("Par am")]
    public class Param
    {
    [XmlAttribute("i d")]
    public string id;
    }

    HTH

    Ollie Riches



    "kishore" <vkbulusu@gmail .comwrote in message
    news:1170741916 .912683.184600@ j27g2000cwj.goo glegroups.com.. .
    Hi
    I have a file similar to below
    >
    >
    <filter>
    <param id="xx">This is test</param>
    <param id="yy">This is another test </param>
    </filter>
    >
    I created classes as below
    >
    [XmlRoot("filter ")]
    public class Filter
    {
    [XmlElement("par am", typeof(Param))]
    Param [] params;
    }
    >
    public class Param
    {
    [XmlAttribute("i d")]
    public string id;
    }
    >
    >
    All this is working fine. But I am not sure how to get the inner texts
    from the Param element. How can I get it through serialization?
    >
    Please help.
    >
    Thanks in advance.
    >

    Comment

    • kishore

      #3
      Re: Extracting innertext and attribute using XmlSerializer

      Hi Ollie,
      Thanks for the reply. Even if i could get hold of the inner text, i
      could extract the value on my own. I don't see a way to get it out?
      I believe when deserialized (convert from xml file to object), it
      should be reading even the innertext also right?
      How do i get hold of it?

      Thanks
      Kishore


      On Feb 6, 2:49 am, "Ollie Riches" <ollie_ric...@h otmail.comwrote :
      Xml serialisation is only going serialise the state of an object to xml it
      does not provide any mechanism to recurse the xml you will have to use an
      xml query tool for that.
      >
      Also I believe you should be using the XmlArrayAttribu te on your array:
      >
      [XmlRoot("filter ")]
      public class Filter
      {
      [XmlArray(Elemen tName = "Params")
      Param [] params;
      >
      }
      >
      [XmlElement("Par am")]
      public class Param
      {
      [XmlAttribute("i d")]
      public string id;
      >
      }
      >
      HTH
      >
      Ollie Riches
      >
      "kishore" <vkbul...@gmail .comwrote in message
      >
      news:1170741916 .912683.184600@ j27g2000cwj.goo glegroups.com.. .
      >
      >
      >
      Hi
      I have a file similar to below
      >
      <filter>
      <param id="xx">This is test</param>
      <param id="yy">This is another test </param>
      </filter>
      >
      I created classes as below
      >
      [XmlRoot("filter ")]
      public class Filter
      {
      [XmlElement("par am", typeof(Param))]
      Param [] params;
      }
      >
      public class Param
      {
      [XmlAttribute("i d")]
      public string id;
      }
      >
      All this is working fine. But I am not sure how to get the inner texts
      from the Param element. How can I get it through serialization?
      >
      Please help.
      >
      Thanks in advance.- Hide quoted text -
      >
      - Show quoted text -

      Comment

      • Samuel R. Neff

        #4
        Re: Extracting innertext and attribute using XmlSerializer


        declare a Text field on Param:

        public class Param {
        [XmlAttribute("i d")]
        public string id;

        [XmlText]
        public string text;
        }

        HTH,

        Sam


        ------------------------------------------------------------
        We're hiring! B-Line Medical is seeking Mid/Sr. .NET
        Developers for exciting positions in medical product
        development in MD/DC. Work with a variety of technologies
        in a relaxed team environment. See ads on Dice.com.


        On 5 Feb 2007 22:05:16 -0800, "kishore" <vkbulusu@gmail .comwrote:
        >Hi
        >I have a file similar to below
        >
        >
        ><filter>
        <param id="xx">This is test</param>
        <param id="yy">This is another test </param>
        ></filter>
        >
        >I created classes as below
        >
        >[XmlRoot("filter ")]
        >public class Filter
        >{
        [XmlElement("par am", typeof(Param))]
        Param [] params;
        >}
        >
        >public class Param
        >{
        [XmlAttribute("i d")]
        public string id;
        >}
        >
        >
        >All this is working fine. But I am not sure how to get the inner texts
        >from the Param element. How can I get it through serialization?
        >
        >Please help.
        >
        >Thanks in advance.

        Comment

        • kishore

          #5
          Re: Extracting innertext and attribute using XmlSerializer

          Thanks Samuel. That was what i was looking for.

          Kishore

          On Feb 6, 11:43 am, Samuel R. Neff <samueln...@nom ail.comwrote:
          declare a Text field on Param:
          >
          public class Param {
          [XmlAttribute("i d")]
          public string id;
          >
          [XmlText]
          public string text;
          >
          }
          >
          HTH,
          >
          Sam
          >
          ------------------------------------------------------------
          We're hiring! B-Line Medical is seeking Mid/Sr. .NET
          Developers for exciting positions in medical product
          development in MD/DC. Work with a variety of technologies
          in a relaxed team environment. See ads on Dice.com.
          >
          On 5 Feb 2007 22:05:16 -0800, "kishore" <vkbul...@gmail .comwrote:
          >
          >
          >
          Hi
          I have a file similar to below
          >
          <filter>
          <param id="xx">This is test</param>
          <param id="yy">This is another test </param>
          </filter>
          >
          I created classes as below
          >
          [XmlRoot("filter ")]
          public class Filter
          {
          [XmlElement("par am", typeof(Param))]
          Param [] params;
          }
          >
          public class Param
          {
          [XmlAttribute("i d")]
          public string id;
          }
          >
          All this is working fine. But I am not sure how to get the inner texts
          from the Param element. How can I get it through serialization?
          >
          Please help.
          >
          Thanks in advance.- Hide quoted text -
          >
          - Show quoted text -

          Comment

          Working...