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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:45:22+00:00 2026-05-11T22:45:22+00:00

I’m trying to figure out how to properly serialize my XmlDocument and send it

  • 0

I’m trying to figure out how to properly serialize my XmlDocument and send it via a HTTPWebRequest object.

Here’s what I have thus far:

Stream requestStream;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://wwwcie.ups.com/ups.app/xml/Track");
request.Method = "POST";

request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
requestStream = request.GetRequestStream();

XmlSerializerNamespaces xsm = new XmlSerializerNamespaces();
xsm.Add("", ""); // remove namespace
XmlSerializer ser = new XmlSerializer(xmlRequest.GetType());
ser.Serialize(requestStream, xmlRequest);

requestStream.Write(postData, 0, postData.Length);
requestStream.Close();

A few things I’m uncertain about. I have 2 XmlDocuments I need to send in the same HTTPWebRequest. I’ve tried before to convert the XmlDocuments to strings and just concatenate them (to send the string) but when I used the StringBuilder / Writer it adds:

  <?xml version="1.0" encoding="utf-8" ?> 
  <string xmlns="http://myNameSpace/">

I already have the declaration in my XmlDocument objects so now its in there twice, and I cannot have the <string... part in there. Is it easier to convert the XmlDocuments to strings then concatenate them and send that or is there a easy way to send the XmlDocuments as they are?

Edit:

See C# XmlDocument Nodes
When I try to convert one of my XmlDocuments to a string it shows up as

  <?xml version="1.0" encoding="utf-8" ?> 
  <string xmlns="http://myNamespace/">
      <TrackRequest>
         <Request>
            <TransactionReference>
                <CustomerContext>whatever</CustomerContext>
            </TransactionReference>
         </Request>
         <TrackingNumber>123</TrackingNumber>
      </TrackRequest>
   </string> 

I want my root to be <TrackRequest>

  • 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-11T22:45:23+00:00Added an answer on May 11, 2026 at 10:45 pm

    I’m guessing this question is related to the previous one about 2 xml documents not being able to be combined into one document without wrapping them both in a root node first (C# XmlDocument Nodes).

    If that is the case then you don’t want to be serialising the XmlDocuments and sending them to the WebService. Serializing the objects is for transporting/storing the actual object, not the data. You want to just send the webservice the data not the object so just concatenate the two xml documents and send that.

    use XmlDocument.OuterXml to get the XmlDocument as a string. ie:
    
    XmlDocument doc1 = new XmlDocument();
    doc.LoadXml("Some XML");
    XmlDocument doc2 = new XmlDocument();
    doc2.LoadXml("Some other XML");
    StringBuilder sb = new StringBuilder();
    sb.Append(doc1.OuterXml);
    sb.Append(doc2.OuterXml);
    

    The just send sb.ToString() to the WebService.

    Hope I haven’t got completely the wrong end of the stick.

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

Sidebar

Ask A Question

Stats

  • Questions 166k
  • Answers 166k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would call it 'twice is better'. It's made like… May 12, 2026 at 1:16 pm
  • Editorial Team
    Editorial Team added an answer The exception is always thrown by XmlDocument.Load as expected. It's… May 12, 2026 at 1:16 pm
  • Editorial Team
    Editorial Team added an answer I succeeded in removing the "group.edit" actions (Copy/Paste) and I've… May 12, 2026 at 1:16 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.