Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

xml add prefix

Posted on 2014-10-17
5
Medium Priority
?
101 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

705 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