the idea need return list of announcements , list of videos string web service. i'm having problems putting lists xml schema.
here's xml schema:
<?xml version="1.0" encoding="utf-8"?> <xs:schema id="welcomescreenschema" elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:attribute name="id" type="xs:int"/> <xs:attribute name="added" type="xs:datetime"/> <xs:element name="welcomescreen"> <xs:complextype> <xs:all> <xs:element ref="announcements" maxoccurs="1" minoccurs="1" /> <xs:element ref="videos" maxoccurs="1" minoccurs="1" /> </xs:all> </xs:complextype> </xs:element> <xs:element name="announcements"> <xs:complextype> <xs:sequence> <xs:element ref="announcement" maxoccurs="unbounded" minoccurs="0"/> </xs:sequence> </xs:complextype> </xs:element> <xs:element name="videos"> <xs:complextype> <xs:sequence> <xs:element ref="video" maxoccurs="unbounded" minoccurs="0"/> </xs:sequence> </xs:complextype> </xs:element> <xs:element name="announcement"> <xs:complextype> <xs:attribute ref="id" use="required"/> <xs:attribute ref="added" use="required"/> <xs:attribute name="html" type="xs:string" use="required"/> </xs:complextype> </xs:element> <xs:element name="video"> <xs:complextype> <xs:attribute ref="id" use="required"/> <xs:attribute ref="added" use="required"/> <xs:attribute name="url" type="xs:string" use="required"/> <xs:attribute name="title" type="xs:string" use="required"/> <xs:attribute name="description" type="xs:string" use="required"/> </xs:complextype> </xs:element> </xs:schema>
i'm populating data using following c#:
xmlobject result = new xmlobject("c:\path\to\schema.xsd"); result.add(new xelement("welcomescreen")); result.root.add(new xelement("announcements")); result.root.add(new xelement("videos")); result.root.element("announcements").add(new xelement("announcement", new xattribute("id", convert.tostring(id)), new xattribute("html", html), new xattribute("added", added) )); result.root.element("videos").add(new xelement("video", new xattribute("id", convert.tostring(id)), new xattribute("html", url), new xattribute("html", title), new xattribute("html", description), new xattribute("added", added) ));
the lines add announcement
, video
elements, inside loops i'm reading info database, excluded code brevity.
it loads 3 announcement
elements schema without problem. when tries load first video
element, crashes giving following error:
system.exception unhandled hresult=-2146233088 message=error getting welcome screen info db. : system.invalidoperationexception: duplicate attribute. @ system.xml.linq.xelement.addattributeskipnotify(xattribute a) @ system.xml.linq.xcontainer.addcontentskipnotify(object content) @ system.xml.linq.xcontainer.addcontentskipnotify(object content)
you adding same attribute multiple times, not allowed
result.root.element("videos").add(new xelement("video", new xattribute("id", convert.tostring(id)), new xattribute("html", url), new xattribute("html", title), new xattribute("html", description), new xattribute("added", added)
Comments
Post a Comment