Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Suppose, I have the following xml schema,

HTML
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Tab1">
<xs:complextype>
<xs:sequence>
<xs:element minoccurs="0" maxoccurs="10" name="Test1" type="xs:string" />
<xs:element minoccurs="0" maxoccurs="10" name="Test2" type="xs:string" />
<xs:element minoccurs="0" maxoccurs="10" name="Test3" type="xs:int" />
</xs:sequence>
</xs:complextype>
</xs:element>
</xs:schema>


then, I have to add some additional values with each element
(Eg: state="kerala" url="mylinkurl")

So the final xml schema output will be as follows:
(see the element tags)

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Tab1">
<xs:complextype>
<xs:sequence>
<xs:element minoccurs="0" maxoccurs="10" name="Test1" type="xs:string" state="kerala" url="mylinkurl" />
<xs:element minoccurs="0" maxoccurs="10" name="Test2" type="xs:string" state="tamilnadu" url="mylinkurl" />
<xs:element minoccurs="0" maxoccurs="10" name="Test3" type="xs:int" />
</xs:sequence>
</xs:complextype>
</xs:element>
</xs:schema>


How can add these name & value programmatically (using c#)? Please provide a sample code.
Posted
Updated 1-Nov-11 7:06am
v2
Comments
fjdiewornncalwe 1-Nov-11 13:07pm    
Please make some attempt to do your own homework. If you have specific issues with your code, ask that here and we'll be glad to help. We will NOT do your work for you as you will learn nothing by that and none of us who are professional developers will want to work with you.
[no name] 1-Nov-11 15:14pm    
Just out of curiousity why did you assume this is homework?
I never did schema stuff in school and I am glad I didn't as the framework does all of the work for you now.

1 solution

Take a look at the XElement[^] class.

With it you can add new XElements and XAttributes along with their values to an existing XElement.
 
Share this answer
 
Comments
Member 4732313 1-Nov-11 22:27pm    
Is it possible using System.Xml.Schema classes?
[no name] 2-Nov-11 12:07pm    
Which class? Why?
XElement works great. Why not use it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900