I am trying to use XmlReader to parse a file and set each element's attributes to variables using reader.GetAttribute("atrribute_name"), but the elements may or may not actually have that attribute present, so some elements give me an error...I would have expected it would just return null when the attribute is not present, but instead it throws errors.
Here's the full exception:
System.Xml.Schema.XmlSchemaException: The 'opacity' attribute is not declared.
at System.Xml.XmlValidatingReaderImpl.InternalValidationCallback(Object sender, ValidationEventArgs e)
at System.Xml.Schema.BaseValidator.SendValidationEvent(XmlSchemaException e, XmlSeverityType severity)
at System.Xml.Schema.BaseValidator.SendValidationEvent(XmlSchemaException e)
at System.Xml.Schema.DtdValidator.ValidateStartElement()
at System.Xml.Schema.DtdValidator.ProcessElement()
at System.Xml.Schema.DtdValidator.ValidateElement()
at System.Xml.Schema.DtdValidator.Validate()
at System.Xml.XmlValidatingReaderImpl.ProcessCoreReaderEvent()
at System.Xml.XmlValidatingReaderImpl.Read()
at Squared.Tiled.Map.Load(String filename, ContentManager content) in C:\Users\Stephen\Documents\Visual Studio 2008\Projects\Tiled\Tiled.cs:line 650
and here's the xml content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map SYSTEM "http://mapeditor.org/dtd/1.0/map.dtd">
<map version="1.0" orientation="orthogonal" width="32" height="32" tilewidth="32" tileheight="32">
<tileset name="Untitled" firstgid="1" tilewidth="32" tileheight="32">
<image source="tiles.png"/>
</tileset>
<layer name="" width="32" height="32" opacity="0.72">
<data encoding="base64" compression="gzip">
H4sIAAAAAAAAAO3DAQkAAAwEofv+pddjKLhqqqqq6usHHB1pSAAQAAA=
</data>
</layer>
<layer name="Layer 1" width="32" height="32">
<properties>
<property name="layermeta" value="layervalue"/>
</properties>
<data encoding="base64" compression="gzip">
H4sIAAAAAAAAAO2UUQrAMAhD+7P7X3nsbwydibrJRh6UQloatbZrzbMZI9KZc5g4EB3dx9Lhn8m707+C5cP2ReX+p7ByuK55WlQz1P9u9vZFOkrVJ6pXxR/pM/TcjD+in9e/1vsHXtzV/Cfqn+GJ+2f9u+qfgX3Pf/v/hRBCiLfZAUDgXx4AEAAA
</data>
</layer>
</map>
opacity may or may not be present in each layer, along with several other attributes.