Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating XmlElment of type <sys:String></sys:String> with code in c#

Status
Not open for further replies.

kevz83

Programmer
Jan 28, 2008
3
US
Hi All,

I am trying to create a XML Element in C# of the form
<sys:String x:Key="MyGroup2_SuperTip">Group 2 supertip en</sys:String>

where
xmlns:x=" xmlns:sys="clr-namespace:System;assembly=mscorlib"

are specified in the header already.
But when i do

XmlElement e1 = xmldoc.CreateElement("sys:String");
e1.SetAttribute("x:Key", "check2_Label");
e1.InnerText = "check 2 label en";

i get
<String Key="check2_Label" xmlns="">check 2 label en</String>

whereas i want
<sys:String x:Key="check2_Label" xmlns="">check 2 label en</sys:String>

Any Help will be appreciated

Thanks.
 
Should check out the overload list. Something like this.

[tt]XmlElement e1 = xmldoc.CreateElement("sys","String","clr-namespace:System;assembly=mscorlib");
e1.SetAttribute("Key","[ignore][/ignore]","check2_Label");
e1.InnerText = "check 2 label en";
[/tt]
 
but this will give me
<sys:String afc:Key="check2_Label" xmlns:sys="somevalue" xmlns:afc="somevalue">check 2 label en</sys:String>

whereas i want it
<sys:String x:Key="check2_Label">check 2 label en</sys:String>

where sys and x are the xmlns mentioned in the top level already
 
Upon re-read, since e1 is meant to be a newly created element, the attribute Key is nowhere created yet, hence that piece of SetAttribute is wrong, sorry! Do this instead?
[tt]
XmlAttribute attr=e1.SetAttributeNode("Key","[ignore][/ignore]");
attr.Value="check2_Label";
[/tt]
 
Right but even after doing this i will get something like
<sys:String afc:Key="check2_Label" xmlns:sys="somevalue" xmlns:afc="somevalue">check 2 label en</sys:String>

but i want
<sys:String x:Key="check2_Label">check 2 label en</sys:String>

i dont want xmlns displayed as it is already displayed at the top of the file
 
I don't know... I just ask myself does inheritence of namespace work no more? why then the "header" does not do its job?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top