Solved

xml add prefix

Posted on 2014-10-17
5
95 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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