write key value pair XMl in c#

Hi Experts,
            
      I have xml written in the classic ASP and I need to write the same in the c#. Could you please help on this ?
            

      ' /////////////////            Key/Value XML      /////////////////
      str="<?xml version=""1.0"" encoding=""UTF-16"" ?><SessionData>"
      str=str&"<SessionPair><Name>EmployeeName</Name><Value>"&XMLEncode(Session("Name"))&"</Value></SessionPair>"
      str=str&"<SessionPair><Name>EmployeeCode</Name><Value>"&XMLEncode(Request.Form("EmpCode"))&"</Value></SessionPair>"
      str=str&"<SessionPair><Name>EmployeeAddress</Name><Value>"&XMLEncode(Request.Form("Add"))&"</Value></SessionPair>"
      str=str&"</SessionData>"
      'XML escape any query strings.
      str = Replace(str, "&", "&amp;")

      I was trying below but it didn't work as getting many compile time error.

       StringBuilder sbmenuModelXML = null;
         sbmenuModelXML = new StringBuilder();

     sbmenuModelXML.Append("<?xml version=""1.0"" encoding=""UTF-16"" ?><SessionData>");
    sbmenuModelXML.Append("<SessionPair><Name>EmployeeName</Name><Value>"+XmlConvert.EncodeName(EmployeeName)+"</Value></SessionPair>");
    sbmenuModelXML.Append("<SessionPair><Name>EmployeeCode</Name><Value>"+XmlConvert.EncodeName(EmployeeCode)+"</Value></SessionPair>");
    sbmenuModelXML.Append("<SessionPair><Name>EmployeeAddress</Name><Value>"+XmlConvert.EncodeName(EmployeeAddress)+"</Value></SessionPair>");
    sbmenuModelXML.Append("</SessionData>");
satmishaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zc2Commented:
What are the errors? I only can see one problem - C# uses different escaping method that VB. So, instead of
     sbmenuModelXML.Append("<?xml version=""1.0"" encoding=""UTF-16"" ?><SessionData>");

Open in new window

it should be
     sbmenuModelXML.Append("<?xml version=\"1.0\" encoding=\"UTF-16\" ?><SessionData>");

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
satmishaAuthor Commented:
Thanks zc2, it worked.

Only issue i found was like at the end my XML contains beginning and ending characters i.e. {} like in given XML. How could I get rid of them too..?

{      
            <?xml version="1.0" encoding="UTF-16" ?><SessionData>
            <SessionPair><Name>EmpName</Name><Value></Value></SessionPair>
            <SessionPair><Name>EmpCode</Name><Value></Value></SessionPair>
            <SessionPair><Name>Salary</Name><Value></Value></SessionPair>
            </SessionPair>
      }
satmishaAuthor Commented:
its done i guess...I simply need to convert that to in string. Thanks Pal for your quick reply.
satmishaAuthor Commented:
Zc2 suggestion worked..
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.