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

  • Home
  • SEARCH
  • 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 663937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:32:39+00:00 2026-05-13T23:32:39+00:00

In my application I have a PacketList class and Packet class. I’d like to

  • 0

In my application I have a PacketList class and Packet class. I’d like to be able to use the serialization helpers on PacketList to come up with something like the desired output, but have no idea what direction to go in.

I am writing a program to imitate a server which has a peculiar protocol for sending data.

Client sends data with format: COMMAND|ARGUMENT_0|ARGUMENT_1|ARGUMENT_2|...|ARGUMENT_N\0. Where COMMAND could be something like MOVE or LOGIN.

The server would respond in the format:

<p c='COUNT'>
    <m p='N' p0='COMMAND_0' p1='ARUGMENT_0' ... pN='ARGUMENT_N'/>
    <m p='N' p0='COMMAND_1' p1='ARUGMENT_0' ... pN='ARGUMENT_N'/>
    <m p='N' p0='COMMAND_2' p1='ARUGMENT_0' ... pN='ARGUMENT_N'/>
    <m p='N' p0='COMMAND_3' p1='ARUGMENT_0' ... pN='ARGUMENT_N'/>
    ...
    <m p='N' p0='COMMAND_COUNT' p1='ARUGMENT_0' ... pN='ARGUMENT_N'/>
</p>

Where COMMAND_0 could be something like UPDATE_POSITION or AUTHENTICATED.

Yes, this is a silly way of doing things. No, I don’t know why it’s done this way. No, I can’t change it.

Anyways, I am looking to emulate the way that the server sends the packet back to the client. What I have gotten so far is:

XmlWriterSettings _Settings = new XmlWriterSettings {
    OmitXmlDeclaration = true,
    Indent = true
};
StringBuilder _Xml = new StringBuilder();
XmlWriter _Writer = XmlWriter.Create(_Xml, _Settings);
_Writer.WriteStartElement("p");
    _Writer.WriteAttributeString("c", "1");
    _Writer.WriteStartElement("m");
        _Writer.WriteAttributeString("p", "2");
        _Writer.WriteAttributeString("p0", "COMMAND");
        _Writer.WriteAttributeString("p1", "ARGUMENT_0");
        _Writer.WriteAttributeString("p2", "ARGUMENT_1");
    _Writer.WriteEndElement(); // </m>
_Writer.WriteEndElement(); // </p>
_Writer.Flush();
Console.WriteLine(_Xml.ToString());

This works properly and outputs:

<p c="1">
  <m p="2" p0="COMMAND" p1="ARGUMENT_0" p2="ARGUMENT_1" />
</p>

However, I’d like to implement this in a cleaner way.

My PacketList basically contains a list of Packets, and Packet contains a String _Command and String[] _Arguments.

If anyone could guide me in the right direction it would be much appreciated.

  • 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-05-13T23:32:39+00:00Added an answer on May 13, 2026 at 11:32 pm

    The way you are currently doing it is the best. I would say to use the XmlSerializer and decorate your Packet and PacketList class’s properties with the appropriate Xml*Attribute attributes to control the way the output is formatted, but since you need to write attributes corresponding to a collection (p0, p1, p2, etc.) this will not work.

    Since you need to write such a weird format, it makes sense to write it manually the way you currently are.

    Andrew

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
In my application I have TextBox in a FormView bound to a LinqDataSource like
In my application I have a Customer class and an Address class. The Customer
I have an game application I have written for Windows Mobile and I want
In my application I have a DataGridView control that displays data for the selected
In my application I have a window which I popup with small messages on
In my current application I have a form that requires the user to enter
In my VC++ application I have an embedded browser (MSHTML). It works fine and
In my iPhone application I have a table view. When user taps any row,
In my application I have a UITextField inside a UITableViewCell . If I click

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.