diff --git a/RDFSharp/Model/Serializers/RDFXml.cs b/RDFSharp/Model/Serializers/RDFXml.cs index 2059bdb9..6d79f202 100644 --- a/RDFSharp/Model/Serializers/RDFXml.cs +++ b/RDFSharp/Model/Serializers/RDFXml.cs @@ -430,7 +430,8 @@ internal static RDFGraph Deserialize(Stream inputStream) Uri xmlBase = null; if (xmlnsAttrs != null && xmlnsAttrs.Count > 0) { - var xmlBaseAttr = (rdfRDF.Attributes["xml:base"] ?? rdfRDF.Attributes["xmlns"]); + var xmlBaseAttr = (rdfRDF.Attributes?[RDFVocabulary.XML.PREFIX + ":base"] + ?? rdfRDF.Attributes?["xmlns"]); if (xmlBaseAttr != null) { xmlBase = RDFModelUtilities.GetUriFromString(xmlBaseAttr.Value); @@ -851,12 +852,12 @@ private static XmlAttribute GetRdfAboutAttribute(XmlNode subjNode) { //rdf:about XmlAttribute rdfAbout = - (subjNode.Attributes[RDFVocabulary.RDF.PREFIX + ":about"] ?? - (subjNode.Attributes["about"] ?? - (subjNode.Attributes[RDFVocabulary.RDF.PREFIX + ":nodeID"] ?? - (subjNode.Attributes["nodeID"] ?? - (subjNode.Attributes[RDFVocabulary.RDF.PREFIX + ":ID"] ?? - subjNode.Attributes["ID"]))))); + (subjNode.Attributes?[RDFVocabulary.RDF.PREFIX + ":about"] ?? + (subjNode.Attributes?["about"] ?? + (subjNode.Attributes?[RDFVocabulary.RDF.PREFIX + ":nodeID"] ?? + (subjNode.Attributes?["nodeID"] ?? + (subjNode.Attributes?[RDFVocabulary.RDF.PREFIX + ":ID"] ?? + subjNode.Attributes?["ID"]))))); return rdfAbout; } @@ -868,10 +869,10 @@ private static XmlAttribute GetRdfResourceAttribute(XmlNode predNode) { //rdf:Resource XmlAttribute rdfResource = - (predNode.Attributes[RDFVocabulary.RDF.PREFIX + ":resource"] ?? - (predNode.Attributes["resource"] ?? - (predNode.Attributes[RDFVocabulary.RDF.PREFIX + ":nodeID"] ?? - predNode.Attributes["nodeID"]))); + (predNode.Attributes?[RDFVocabulary.RDF.PREFIX + ":resource"] ?? + (predNode.Attributes?["resource"] ?? + (predNode.Attributes?[RDFVocabulary.RDF.PREFIX + ":nodeID"] ?? + predNode.Attributes?["nodeID"]))); return rdfResource; } @@ -883,8 +884,8 @@ private static XmlAttribute GetRdfDatatypeAttribute(XmlNode predNode) { //rdf:datatype XmlAttribute rdfDatatype = - (predNode.Attributes[RDFVocabulary.RDF.PREFIX + ":datatype"] ?? - predNode.Attributes["datatype"]); + (predNode.Attributes?[RDFVocabulary.RDF.PREFIX + ":datatype"] ?? + predNode.Attributes?["datatype"]); return rdfDatatype; } @@ -896,8 +897,8 @@ private static XmlAttribute GetXmlLangAttribute(XmlNode predNode) { //xml:lang XmlAttribute xmlLang = - (predNode.Attributes[RDFVocabulary.XML.PREFIX + ":lang"] ?? - predNode.Attributes["lang"]); + (predNode.Attributes?[RDFVocabulary.XML.PREFIX + ":lang"] ?? + predNode.Attributes?["lang"]); return xmlLang; } @@ -908,8 +909,8 @@ private static XmlAttribute GetXmlLangAttribute(XmlNode predNode) private static XmlAttribute GetParseTypeCollectionAttribute(XmlNode predNode) { XmlAttribute rdfCollection = - (predNode.Attributes[RDFVocabulary.RDF.PREFIX + ":parseType"] ?? - predNode.Attributes["parseType"]); + (predNode.Attributes?[RDFVocabulary.RDF.PREFIX + ":parseType"] ?? + predNode.Attributes?["parseType"]); return ((rdfCollection != null && rdfCollection.Value.Equals("Collection", StringComparison.Ordinal)) ? rdfCollection : null); } @@ -920,8 +921,8 @@ private static XmlAttribute GetParseTypeCollectionAttribute(XmlNode predNode) private static XmlAttribute GetParseTypeLiteralAttribute(XmlNode predNode) { XmlAttribute rdfLiteral = - (predNode.Attributes[RDFVocabulary.RDF.PREFIX + ":parseType"] ?? - predNode.Attributes["parseType"]); + (predNode.Attributes?[RDFVocabulary.RDF.PREFIX + ":parseType"] ?? + predNode.Attributes?["parseType"]); return ((rdfLiteral != null && rdfLiteral.Value.Equals("Literal", StringComparison.Ordinal)) ? rdfLiteral : null); }