static private CreateAttribute ( |
||
doc | ||
name | string | |
ns | string | |
Résultat |
void AddAllQualifiersTo(XmlNode xml) { if (qualifiers == null) { return; } foreach (var collection in qualifiers.Values) { foreach (XmpNode node in collection.Values) { XmlAttribute attr = XmpTag.CreateAttribute(xml.OwnerDocument, node.Name, node.Namespace); attr.Value = node.Value; xml.Attributes.Append(attr); } } }
/// <summary> /// Renders the current instance as child of the given node to the /// given <see cref="XmlNode"/> /// </summary> /// <param name="parent"> /// A <see cref="XmlNode"/> to render the current instance as child of. /// </param> public void RenderInto(XmlNode parent) { if (IsRootNode) { AddAllChildrenTo(parent); } else if (IsReallySimpleType && parent.Attributes.GetNamedItem(XmpTag.PARSE_TYPE_URI, XmpTag.RDF_NS) == null) { // Simple values can be added as attributes of the parent node. Not allowed when the parent has an rdf:parseType. XmlAttribute attr = XmpTag.CreateAttribute(parent.OwnerDocument, Name, Namespace); attr.Value = Value; parent.Attributes.Append(attr); } else if (Type == XmpNodeType.Simple || Type == XmpNodeType.Struct) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); node.InnerText = Value; if (Type == XmpNodeType.Struct) { // Structured types are always handled as a parseType=Resource node. This way, IsReallySimpleType will // not match for child nodes, which makes sure they are added as extra nodes to this node. Does the // trick well, unit tests that prove this are in XmpSpecTest. XmlAttribute attr = XmpTag.CreateAttribute(parent.OwnerDocument, XmpTag.PARSE_TYPE_URI, XmpTag.RDF_NS); attr.Value = "Resource"; node.Attributes.Append(attr); } AddAllQualifiersTo(node); AddAllChildrenTo(node); parent.AppendChild(node); } else if (Type == XmpNodeType.Bag) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); if (QualifierCount > 0) { throw new NotImplementedException(); } var bag = XmpTag.CreateNode(parent.OwnerDocument, XmpTag.BAG_URI, XmpTag.RDF_NS); foreach (var child in Children) { child.RenderInto(bag); } node.AppendChild(bag); parent.AppendChild(node); } else if (Type == XmpNodeType.Alt) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); if (QualifierCount > 0) { throw new NotImplementedException(); } var bag = XmpTag.CreateNode(parent.OwnerDocument, XmpTag.ALT_URI, XmpTag.RDF_NS); foreach (var child in Children) { child.RenderInto(bag); } node.AppendChild(bag); parent.AppendChild(node); } else if (Type == XmpNodeType.Seq) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); if (QualifierCount > 0) { throw new NotImplementedException(); } var bag = XmpTag.CreateNode(parent.OwnerDocument, XmpTag.SEQ_URI, XmpTag.RDF_NS); foreach (var child in Children) { child.RenderInto(bag); } node.AppendChild(bag); parent.AppendChild(node); } else { // Probably some combination of things we don't fully cover yet. Dump(); throw new NotImplementedException(); } }
public void RenderInto(XmlNode parent) { if (IsRootNode) { AddAllChildrenTo(parent); } else if (IsReallySimpleType && parent.Attributes.GetNamedItem(XmpTag.PARSE_TYPE_URI, XmpTag.RDF_NS) == null) { XmlAttribute attr = XmpTag.CreateAttribute(parent.OwnerDocument, Name, Namespace); attr.Value = Value; parent.Attributes.Append(attr); } else if (Type == XmpNodeType.Simple || Type == XmpNodeType.Struct) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); node.InnerText = Value; if (Type == XmpNodeType.Struct) { XmlAttribute attr = XmpTag.CreateAttribute(parent.OwnerDocument, XmpTag.PARSE_TYPE_URI, XmpTag.RDF_NS); attr.Value = "Resource"; node.Attributes.Append(attr); } AddAllQualifiersTo(node); AddAllChildrenTo(node); parent.AppendChild(node); } else if (Type == XmpNodeType.Bag) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); if (QualifierCount > 0) { throw new NotImplementedException(); } var bag = XmpTag.CreateNode(parent.OwnerDocument, XmpTag.BAG_URI, XmpTag.RDF_NS); foreach (var child in Children) { child.RenderInto(bag); } node.AppendChild(bag); parent.AppendChild(node); } else if (Type == XmpNodeType.Alt) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); if (QualifierCount > 0) { throw new NotImplementedException(); } var bag = XmpTag.CreateNode(parent.OwnerDocument, XmpTag.ALT_URI, XmpTag.RDF_NS); foreach (var child in Children) { child.RenderInto(bag); } node.AppendChild(bag); parent.AppendChild(node); } else if (Type == XmpNodeType.Seq) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); if (QualifierCount > 0) { throw new NotImplementedException(); } var bag = XmpTag.CreateNode(parent.OwnerDocument, XmpTag.SEQ_URI, XmpTag.RDF_NS); foreach (var child in Children) { child.RenderInto(bag); } node.AppendChild(bag); parent.AppendChild(node); } else { Dump(); throw new NotImplementedException(); } }