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 8006793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:37:46+00:00 2026-06-04T17:37:46+00:00

Is it possible to serialize xml document in C# to produce such tags …

  • 0

Is it possible to serialize xml document in C# to produce such tags

...
<myTag attr="tag">
    this is text
    <a href="http://yaplex.com">link in the same element</a>
</myTag>
...

The only one way I found is have content of myTag as string

myTag.Value = "text <a ...>link</a>"; 

but I want to have it as object in C#, so a-tag will be an object

  • 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-04T17:37:47+00:00Added an answer on June 4, 2026 at 5:37 pm
    public class myTag
    {
        [XmlAttribute]
        public string attr;
        [XmlText]
        public string text;
        public Anchor a;
    }
    
    [XmlRoot("a")]
    public class Anchor
    {
        [XmlAttribute]
        public string href;
        [XmlText]
        public string text;
    }
    

    –

    var obj = new myTag() { 
        attr = "tag", 
        text = "this is text", 
        a = new Anchor() { 
            href = "http://yaplex.com",
            text="link in the same element" 
        } 
    }; 
    
    XmlSerializer ser = new XmlSerializer(typeof(myTag));
    StringWriter wr = new StringWriter();
    XmlWriter writer = XmlTextWriter.Create(wr, new XmlWriterSettings() { OmitXmlDeclaration = true });
    var ns = new XmlSerializerNamespaces();
    ns.Add("","");
    ser.Serialize(writer,obj, ns);
    string result = wr.ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to serialize an object to an XML of this form with
Possible Duplicate: How to (xml) serialize a uri To my knowledge Uri implements ISerializable,
Assuming an XML like this: <my:Root xmlns:my=http://foo/bar> <my:FieldBasic>content</my:FieldBasic> <my:FieldComplex> <html xml:space=preserve xmlns=http://www.w3.org/1999/xhtml> <div><h1>content</h1></div> </html>
i'm trying to serialize DataTable to Json or XML. is it possibly and how?
Is it possible to serialize a non Static Inner class? If yes can you
Is it possible to serialize an object into a string or a byte array
Possible Duplicate: How to serialize an IList<T>? I wish to serialize an class (let's
Is it possible via an attribute of some sort to serialize a string as
Is it possible to specialize this template for any basic_string's? template<class T> struct X
Possible Duplicate: What is the fastest XML parser in PHP? I still need to

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.