Skip to content

Commit

Permalink
More robust detection of subject node element
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesalvo committed Oct 16, 2020
1 parent 1cae589 commit 001b6a3
Showing 1 changed file with 15 additions and 36 deletions.
51 changes: 15 additions & 36 deletions RDFSharp/Model/Serializers/RDFXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -823,11 +823,11 @@ private static RDFResource GetSubjectNode(XmlNode subjNode, Uri xmlBase, RDFGrap
{
RDFResource subj = null;

//If there are attributes, search them for the one representing the subj
//If there are attributes, search for the one describing the subject
if (subjNode.Attributes != null && subjNode.Attributes.Count > 0)
{

//We are interested in finding the "rdf:about" or "rdf:resource" node for the subj
//We are interested in finding the "rdf:about" or "rdf:resource"
XmlAttribute rdfAbout =
(GetRdfAboutAttribute(subjNode)
?? GetRdfResourceAttribute(subjNode));
Expand All @@ -839,45 +839,24 @@ private static RDFResource GetSubjectNode(XmlNode subjNode, Uri xmlBase, RDFGrap
subj = new RDFResource(rdfAboutValue);
}

//If "rdf:about" attribute has been found for the subj, we must
//check if the node is not a standard "rdf:Description": this is
//the case we can directly build a triple with "rdf:type" pred
if (subj != null && !CheckIfRdfDescriptionNode(subjNode))
{
RDFResource obj = null;
if (subjNode.NamespaceURI == String.Empty)
{
obj = new RDFResource(xmlBase + subjNode.LocalName);
}
else
{
obj = new RDFResource(subjNode.NamespaceURI + subjNode.LocalName);
}
result.AddTriple(new RDFTriple(subj, RDFVocabulary.RDF.TYPE, obj));
}

}

//Otherwise make the subj a blank node
else
{
if (subj == null)
subj = new RDFResource();

//We must check if the node is not a standard "rdf:Description": this is
//the case we can directly build a triple with "rdf:type" pred
if (!CheckIfRdfDescriptionNode(subjNode))
//We must check if the node is not a standard "rdf:Description": this is
//the case we can directly build a triple with "rdf:type" pred
if (!CheckIfRdfDescriptionNode(subjNode))
{
RDFResource obj = null;
if (subjNode.NamespaceURI == String.Empty)
{
RDFResource obj = null;
if (subjNode.NamespaceURI == String.Empty)
{
obj = new RDFResource(xmlBase + subjNode.LocalName);
}
else
{
obj = new RDFResource(subjNode.NamespaceURI + subjNode.LocalName);
}
result.AddTriple(new RDFTriple(subj, RDFVocabulary.RDF.TYPE, obj));
obj = new RDFResource(xmlBase + subjNode.LocalName);
}
else
{
obj = new RDFResource(subjNode.NamespaceURI + subjNode.LocalName);
}
result.AddTriple(new RDFTriple(subj, RDFVocabulary.RDF.TYPE, obj));
}

return subj;
Expand Down

0 comments on commit 001b6a3

Please sign in to comment.