Usign XMLSerializer to add attributes to a Class Member

jack123ishere

New Member
I am attempting to write a WCF service which uses XmlSerialzer to output the xml. I need a specific xml output which is why I am not using DataContract Seriailzer. Specifically I am writing a catalogue service web(csw) which has a defined schema etc.I have been trying to write the classes first and then test what XML is being outputted. This is rather tedious and I may switch to the xsd utility. What I would like to know is can I add xml attributes to other class members or will those decorated xmlattributes only be added to the root element i.e the class name? There seems to be flexibility issues compared to writing the CML by hand using XDocument. Also every time I need to nest elements (not collections) It seems I need to create a new class? Is that right?The output xml I need is:\[code\]<ows:ContactInfo> <ows:OnlineResource xlink:href="mailto:[email protected]"/> </ows:ContactInfo>\[/code\]Here is my class:\[code\] public class ContactInfo { [XmlElement] public string OnlineResource = ""; [XmlElementAttribute(ElementName = "OnlineResource",Namespace = "http://www.w3.org /1999/xlink")] public string href = "mailto:[email protected]"; }\[/code\]which outputs the xml as follows:\[code\]<ows:ContactInfo xlink:href="mailto:[email protected]"><ows:OnlineResource>mailto:[email protected]</ows:OnlineResource></ows:ContactInfo>\[/code\]
 
Back
Top