I have written a little application that can grab part of a page from a
web site. I then want to take this result and be able to serialize it
so that it can be stored as XML. I am storing these "ResultNodes" as
System.Xml.XmlElements but when I try and serialize (serialise) my
result object I get the following exception:
"System.InvalidOperationException" - "There was an error generating the
XML document"
"The type System.Xml.XmlElement may not be used in this context."
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter
xmlWriter, Object o, XmlSerializerNamespaces namespaces, String
encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter
xmlWriter, Object o, XmlSerializerNamespaces namespaces, String
encodingStyle)
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter
xmlWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter
xmlWriter, Object o)
at <My Source Code>
The XSD for my ResultNodes collection is:
<xs:complexType name="ResultNodes">
<xs:sequence>
<xs:element name="ResultNode" type="xs:anyType" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
Can System.Xml.XmlElements be serialized? If not, what is the standard
solution for wrapping up nodes so that a result XML document may look
something like the following?
<?xml version="1.0"?>
<Root>
<Name>An example</Name>
<ResultNodes>
<!-- Grab the title element from a page -->
<ResultNode>
<title>Leggetter.co.uk</title>
</ResultNode>
<!-- Grab the body element from a page -->
<ResultNode>
<body>
<!-- An assortment of elements and things could be here
-->
</body>
</ResultNode>
<ResultNode>
<!-- Grab the entire page -->
<html>
<!-- ... -->
</html>
</ResultNode>
</ResultNodes>
</Root>
Many thanks