以下問題反序列化時,XML文件如何解決在反序列化xml文件中生成的問題?
{System.InvalidOperationException: There is an error in XML document (3, 514). ---> System.NotSupportedException: XLinq
at System.Xml.Serialization.XmlSerializationReader.ReadXmlNodes(Boolean elementCanBeType)
at System.Xml.Serialization.XmlSerializationReader.ReadTypedPrimitive(XmlQualifiedName type, Boolean elementCanBeType)
at System.Xml.Serialization.XmlSerializationReader.ReadTypedPrimitive(XmlQualifiedName type)
這是XML,我試圖解析,
<ns0:Response xmlns:ns0="urn:ae:testwebsite:uniqueness:genericcontentsrs:1">
<GenericContents>
<ModuleId>1296</ModuleId>
<Title>Getting around</Title>
<Description>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, <a target="_blank" href="http://google.com">google.com</a>, Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,<br />
<br />Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, TEst&rsquo;s Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</Description>
<BuildingId>0</BuildingId>
<GeoCoordinateX></GeoCoordinateX>
<GeoCoordinateY></GeoCoordinateY>
<MainImage>http://testwebsite.com/testimage.jpg</MainImage>
<PublicLink>http://testwebsite.com/testpage.aspx</PublicLink>
<Subpages>
<Page>
<SSId>10</SSId>
<Title>Tours & tour operators</Title>
<Image>http://testwebsite.com/testimage.jpg</Image>
<ModuleUniqueName>tours.tour.operators</ModuleUniqueName>
</Page>
<Page>
<SSId>7</SSId>
<Title>Taxis</Title>
<Image>http://testwebsite.com/testimage.jpg</Image>
<ModuleUniqueName>taxis</ModuleUniqueName>
</Page>
</Subpages>
<RelatedEntities>
<Entity>
<Id>36694</Id>
<Type>Image</Type>
<TypeDescription>Corniche Road</TypeDescription>
<URL>http://testwebsite.com/testimage.jpg</URL>
<Title>DataFolder/TestImage.jpg</Title>
</Entity>
</RelatedEntities>
</GenericContents>
</ns0:Response>
而且使用下面的類來反序列化,
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "urn:ae:testwebsite:uniqueness:genericcontentsrs:1")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "urn:ae:testwebsite:uniqueness:genericcontentsrs:1", IsNullable = false)]
public partial class Response
{
private GenericContents genericContentsField;
[System.Xml.Serialization.XmlElementAttribute(Namespace = "")]
public GenericContents GenericContents
{
get{return this.genericContentsField;}
set{this.genericContentsField = value;}
}
}
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class GenericContents
{
private ushort moduleIdField;
private string titleField;
private string descriptionField;
private byte buildingIdField;
private object geoCoordinateXField;
private object geoCoordinateYField;
private string mainImageField;
private string publicLinkField;
private GenericContentsPage[] subpagesField;
private GenericContentsRelatedEntities relatedEntitiesField;
public ushort ModuleId
{
get{return this.moduleIdField;}
set{this.moduleIdField = value;}
}
public string Title
{
get{return this.titleField;}
set{this.titleField = value;}
}
public string Description
{
get{return this.descriptionField;}
set{this.descriptionField = value;}
}
public byte BuildingId
{
get{return this.buildingIdField;}
set{this.buildingIdField = value;}
}
public object GeoCoordinateX
{
get{return this.geoCoordinateXField;}
set{this.geoCoordinateXField = value;}
}
public object GeoCoordinateY
{
get{return this.geoCoordinateYField;}
set{this.geoCoordinateYField = value;}
}
public string MainImage
{
get{return this.mainImageField;}
set{this.mainImageField = value;}
}
public string PublicLink
{
get{return this.publicLinkField;}
set{this.publicLinkField = value;}
}
[System.Xml.Serialization.XmlArrayItemAttribute("Page", IsNullable = false)]
public GenericContentsPage[] Subpages
{
get{return this.subpagesField;}
set{this.subpagesField = value;}
}
public GenericContentsRelatedEntities RelatedEntities
{
get{return this.relatedEntitiesField;}
set{this.relatedEntitiesField = value;}
}
}
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class GenericContentsPage
{
private ushort sSIdField;
private string titleField;
private string imageField;
private string moduleUniqueNameField;
public ushort SSId
{
get{return this.sSIdField;}
set{this.sSIdField = value;}
}
public string Title
{
get{return this.titleField;}
set{this.titleField = value;}
}
public string Image
{
get{return this.imageField;}
set{this.imageField = value;}
}
public string ModuleUniqueName
{
get{return this.moduleUniqueNameField;}
set{this.moduleUniqueNameField = value;}
}
}
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class GenericContentsRelatedEntities
{
private GenericContentsRelatedEntitiesEntity entityField;
public GenericContentsRelatedEntitiesEntity Entity
{
get{return this.entityField;}
set{this.entityField = value;}
}
}
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class GenericContentsRelatedEntitiesEntity
{
private ushort idField;
private string typeField;
private string typeDescriptionField;
private string uRLField;
private string titleField;
public ushort Id
{
get{return this.idField;}
set{this.idField = value;}
}
public string Type
{
get{return this.typeField;}
set{this.typeField = value;}
}
public string TypeDescription
{
get{return this.typeDescriptionField;}
set{this.typeDescriptionField = value;}
}
public string URL
{
get{return this.uRLField;}
set{this.uRLField = value;}
}
public string Title
{
get{return this.titleField;}
set{this.titleField = value;}
}
}
幫助發生我解決問題
'&'不是有效的xml實體(它實際上是一個html實體)。你如何生成XML文件?在反序列化之前,您必須更正xml。如果可能的話在源頭。 –
@SteveB:不是預定義的XML實體?有5個預定義的實體:「<」,「>」,「&」,「'」和「"」http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML MSXML表示XML格式良好。 –
我認爲沒有任何問題與entities.i認爲與WP8問題。現在我已經測試,相同的類和desearilizing與WP7應用程序在另一臺機器上工作。是否有任何我缺少WP8? –