Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Using xmlserialization to create an xml document...have a question [modified]

Using xmlserialization to create an xml document...have a question [modified]

Scheduled Pinned Locked Moved C#
databasequestionxmltutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LongRange Shooter
    wrote on last edited by
    #1

    I'm taking data from a database and feeding it into an application that takes an XML file as input. One of their fields is basically an enumerator value so I created a class that would attach the attribute to the field:

        StaticType<int;> contractType;
        ...
    
    \[Serializable\]
    public class StaticType<T>
    {
    	public StaticType( ) { }
    	public StaticType( T initialValue )
    	{
    		internalValue = initialValue;
    		initialValue = index;
    	}
    	private T initialValue;
    	private int initialIndex;
    	\[XmlAttribute(AttributeName="staticValue")\]
    	public T InternalValue
    	{
    		get { return initialValue; }
    		set { initialValue = value; }
    	}
    
    }
    

    The output works great and I get a field as such: <someDataType staticValue="1" /> Here is the question: Reading further into the documentation it looks like I might have to pass the value for some reason as well. So I'm puzzled as to how to construct the class so that my output gets created as: <someDataType staticValue="1">some text value</someDataType> Any ideas?

    modified on Tuesday, February 19, 2008 1:17 PM

    L 1 Reply Last reply
    0
    • L LongRange Shooter

      I'm taking data from a database and feeding it into an application that takes an XML file as input. One of their fields is basically an enumerator value so I created a class that would attach the attribute to the field:

          StaticType<int;> contractType;
          ...
      
      \[Serializable\]
      public class StaticType<T>
      {
      	public StaticType( ) { }
      	public StaticType( T initialValue )
      	{
      		internalValue = initialValue;
      		initialValue = index;
      	}
      	private T initialValue;
      	private int initialIndex;
      	\[XmlAttribute(AttributeName="staticValue")\]
      	public T InternalValue
      	{
      		get { return initialValue; }
      		set { initialValue = value; }
      	}
      
      }
      

      The output works great and I get a field as such: <someDataType staticValue="1" /> Here is the question: Reading further into the documentation it looks like I might have to pass the value for some reason as well. So I'm puzzled as to how to construct the class so that my output gets created as: <someDataType staticValue="1">some text value</someDataType> Any ideas?

      modified on Tuesday, February 19, 2008 1:17 PM

      L Offline
      L Offline
      Le centriste
      wrote on last edited by
      #2

      Using Xml serialization, you cannot have that construct. Instead, it would looks something like: <someDataType staticValue="1"><Value>some text value </Value></someDataType> You would require another property in your object, named Value (or whatever name you chose).

      L 1 Reply Last reply
      0
      • L Le centriste

        Using Xml serialization, you cannot have that construct. Instead, it would looks something like: <someDataType staticValue="1"><Value>some text value </Value></someDataType> You would require another property in your object, named Value (or whatever name you chose).

        L Offline
        L Offline
        LongRange Shooter
        wrote on last edited by
        #3

        Yeh, that was the only solution I saw as well. Thanks.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups