.net - How to use Xelement in this situation -
i have obtain kind of xml :
<ps> <pr> <name>name1</name> <comp> <type>cb</type> <attr> <value>0</value> </attr> </comp> </pr> <sep>sep1</sep> <pr> <name>name2</name> <comp> <type>rb</type> <attr> <value>1</value> </attr> </comp> </pr> <sep>sep2</sep> <pr> <name>name3</name> <comp> <type>com</type> <attr> <value>2</value> </attr> </comp> </pr> <sep>sep3</sep> </ps>
you can see have ps parent of , after have pr , sep in sequence , want maintain sequence. before used xmlelement
showing sep togetehr , pr
together. guess need utilize xelement don't know how utilize them. 1 please explain me or write piece of code create refrence understand hos obtain kind of xml.
my seek : (which not give want)
[xmlroot(elementname = "attr")] public class attr { [xmlelement("type")], public string type { get; set; } [xmlelement("value")] public int value { get; set; } } [xmlroot(elementname = "pr")] public class pr { [xmlelement("name")] public string name { get; set; } [xmlelement("comp")] public list<comp> comp { { homecoming b3; } } private readonly list<comp> b3 = new list<comp>(); } [xmlroot(elementname = "sep")] public class sep { [xmlelement("sep")] public string sep { get; set; } } public void main() { ps pc = new ps() { pr = { new pr { name = "name1", component = { new comp { type = "type1", attr = { new attr { type = "com" } } } } }, { new pr { name = "name2" ,comp = { new comp { type = "type2", attr = { new attr { type = "sl" ....and on} } } } } } } , sep = { new sep { separators = "sep1" ..and on} } }; var xml = pc.toxml(); }
but code dont give sequence want.it shows in xml first sep togther , ps togther(not in sequence) have achieved using xelement static , not utilize class objects "name", "comp", type, value etc. it's this:
var el = new xelement("ps", new xelement("pr", new xelement("name", "name1"), new xelement("comp", new xelement("type", "cb"), new xelement("attr", new xelement("value", 0) ) ) ),//and on..
so not @ utilize class objects. assigne elike xelement("name", "name1") want ps object1 = new ps();
, object1.pr[0].name= "name1";
how accomplish , should maintain same sequence of ps
, sep
well?
.net xml xml-serialization xelement xml-deserialization
No comments:
Post a Comment