Solved

xml add prefix

Posted on 2014-10-17
5
97 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
[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: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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
asp.net get gridview datakey from row command 2 45
Best book for Internet security 4 55
Put File 6 37
advancedDataGridView / cancel / filter / using / button 5 31
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

751 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