Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

xml add prefix

Posted on 2014-10-17
5
Medium Priority
?
104 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:Seven price
  • 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:Seven price
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:
Seven price 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:Seven price
ID: 40403785
tks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 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