// 7.2.21 emptyPropertyElt // start-element ( URI == propertyElementURIs, // attributes == set ( idAttr?, ( resourceAttr | nodeIdAttr )?, propertyAttr* ) ) // end-element() private void ParseEmptyPropertyElement (XmpNode parent, XmlNode node) { if (!node.IsPropertyElement ()) throw new CorruptFileException ("Invalid property"); if (node.HasChildNodes) throw new CorruptFileException (String.Format ("Can't have content in this node! Node: {0}", node.OuterXml)); var rdf_value = node.Attributes.GetNamedItem (VALUE_URI, RDF_NS) as XmlAttribute; var rdf_resource = node.Attributes.GetNamedItem (RESOURCE_URI, RDF_NS) as XmlAttribute; // Options 1 and 2 var simple_prop_val = rdf_value ?? rdf_resource ?? null; if (simple_prop_val != null) { string value = simple_prop_val.InnerText; parent.AddChild (CreateTextPropertyWithQualifiers (node, value)); return; } // Options 3 & 4 var new_node = new XmpNode (node.NamespaceURI, node.LocalName); foreach (XmlAttribute a in node.Attributes) { if (a.Is(RDF_NS, ID_URI) || a.Is(RDF_NS, NODE_ID_URI)) { continue; } else if (a.In (XMLNS_NS)) { continue; } else if (a.Is (XML_NS, LANG_URI)) { new_node.AddQualifier (new XmpNode (XML_NS, LANG_URI, a.InnerText)); } new_node.AddChild (new XmpNode (a.NamespaceURI, a.LocalName, a.InnerText)); } parent.AddChild (new_node); }
// 7.2.16 literalPropertyElt // start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, datatypeAttr?) ) // text() // end-element() private void ParseLiteralPropertyElement (XmpNode parent, XmlNode node) { if (!node.IsPropertyElement ()) throw new CorruptFileException ("Invalid property"); parent.AddChild (CreateTextPropertyWithQualifiers (node, node.InnerText)); }
// 7.2.18 parseTypeResourcePropertyElt // start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseResource ) ) // propertyEltList // end-element() private void ParseTypeResourcePropertyElement (XmpNode parent, XmlNode node) { if (!node.IsPropertyElement ()) throw new CorruptFileException ("Invalid property"); XmpNode new_node = new XmpNode (node.NamespaceURI, node.LocalName); new_node.Type = XmpNodeType.Struct; foreach (XmlNode attr in node.Attributes) { if (attr.Is (XML_NS, LANG_URI)) new_node.AddQualifier (new XmpNode (XML_NS, LANG_URI, attr.InnerText)); } foreach (XmlNode child in node.ChildNodes) { if (child is XmlWhitespace || child is XmlComment) continue; ParsePropertyElement (new_node, child); } parent.AddChild (new_node); }
// 7.2.15 resourcePropertyElt // start-element ( URI == propertyElementURIs, attributes == set ( idAttr? ) ) // ws* nodeElement ws* // end-element() private void ParseResourcePropertyElement (XmpNode parent, XmlNode node) { if (!node.IsPropertyElement ()) throw new CorruptFileException ("Invalid property"); XmpNode new_node = new XmpNode (node.NamespaceURI, node.LocalName); foreach (XmlAttribute attr in node.Attributes) { if (attr.Is (XML_NS, LANG_URI)) { new_node.AddQualifier (new XmpNode (XML_NS, LANG_URI, attr.InnerText)); } else if (attr.Is (RDF_NS, ID_URI) || attr.In (XMLNS_NS)) { continue; } throw new CorruptFileException (String.Format ("Invalid attribute: {0}", attr.OuterXml)); } bool has_xml_children = false; foreach (XmlNode child in node.ChildNodes) { if (child is XmlWhitespace) continue; if (child is XmlText) throw new CorruptFileException ("Can't have text here!"); has_xml_children = true; ParseNodeElement (new_node, child); } if (!has_xml_children) throw new CorruptFileException ("Missing children for resource property element"); parent.AddChild (new_node); }