Solved

xml add prefix

Posted on 2014-10-17
5
90 Views
Last Modified: 2014-10-25
<s:Envelope xmlns:a="http://www.w3.org/" xmlns:s="http://www.w3.org/2003/pe">
  <Header />
</s:Envelope>

Open in new window


I need it to be

<s:Envelope xmlns:a="http://www.w3.org/" xmlns:s="http://www.w3.org/2003/pe">
  <s:Header>
<a:Action s:mustUnderstan="2">some verbage jere</a:Action>
</s:Header>
</s:Envelope>

Open in new window


c# code below
 const string prefix = "s";
            XmlDocument doc = new XmlDocument();
            const string nameSpaceUri = @"http://www.w3.org/2005/08/addressing";
            XmlElement root = doc.CreateElement(prefix, "Envelope", nameSpaceUri);
            root.SetAttribute("xmlns:a", "http://www.w3.org");
            root.SetAttribute("xmlns:s", "http://www.w3.org/2003/pe");
            doc.AppendChild(root);

            XmlElement Head = doc.CreateElement("Header");
            doc.DocumentElement.AppendChild(Head);

Open in new window

0
Comment
Question by:sevensnake77
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:louisfr
ID: 40387879
Try using the prefix and namespace in the CreateElement call:
XmlElement Head = doc.CreateElement(prefix, "Header", "http://www.w3.org/2003/pe");

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40392170
that is not helping me. the
 <s:Header xmlns:s="http://www.w3.org/2003/pe" />

Open in new window


it should be

 <s:Header />

Open in new window

0
 
LVL 11

Expert Comment

by:louisfr
ID: 40392460
When I tried it, the xmlns:s part is not included, since it's already on a parent node.
I'll try again later when I have time.
0
 
LVL 9

Accepted Solution

by:
sevensnake77 earned 0 total points
ID: 40392636
I figured it out. you have to use namespaces.
thanks anyway.
http://msdn.microsoft.com/en-us/library/bb387075.aspx
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 40403785
tks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now