AddChild() публичный Метод

Adds a node as child of the current node
public AddChild ( XmpNode node ) : void
node XmpNode /// A to be add as child ///
Результат void
Пример #1
0
        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);
        }
Пример #2
0
 private void ParseLiteralPropertyElement(XmpNode parent, XmlNode node)
 {
     if (!node.IsPropertyElement())
     {
         throw new CorruptFileException("Invalid property");
     }
     parent.AddChild(CreateTextPropertyWithQualifiers(node, node.InnerText));
 }
Пример #3
0
        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;
            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;
            }
            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);
        }
Пример #4
0
 private void ParseNodeElement(XmpNode parent, XmlNode node)
 {
     if (!node.IsNodeElement())
     {
         throw new CorruptFileException("Unexpected node found, invalid RDF?");
     }
     if (node.Is(RDF_NS, SEQ_URI))
     {
         parent.Type = XmpNodeType.Seq;
     }
     else if (node.Is(RDF_NS, ALT_URI))
     {
         parent.Type = XmpNodeType.Alt;
     }
     else if (node.Is(RDF_NS, BAG_URI))
     {
         parent.Type = XmpNodeType.Bag;
     }
     else if (node.Is(RDF_NS, DESCRIPTION_URI))
     {
         parent.Type = XmpNodeType.Struct;
     }
     else
     {
         throw new Exception("Unknown nodeelement found! Perhaps an unimplemented collection?");
     }
     foreach (XmlAttribute attr in node.Attributes)
     {
         if (attr.In(XMLNS_NS))
         {
             continue;
         }
         if (attr.Is(RDF_NS, ID_URI) || attr.Is(RDF_NS, NODE_ID_URI) || attr.Is(RDF_NS, ABOUT_URI))
         {
             continue;
         }
         if (attr.Is(XML_NS, LANG_URI))
         {
             throw new CorruptFileException("xml:lang is not allowed here!");
         }
         parent.AddChild(new XmpNode(attr.NamespaceURI, attr.LocalName, attr.InnerText));
     }
     foreach (XmlNode child in node.ChildNodes)
     {
         if (child is XmlWhitespace || child is XmlComment)
         {
             continue;
         }
         ParsePropertyElement(parent, child);
     }
 }
Пример #5
0
        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);
        }
Пример #6
0
		// 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
0
		// 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);
		}
Пример #8
0
		// 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));
		}
Пример #9
0
		// 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);
		}
Пример #10
0
		// 7.2.11 nodeElement
		//		start-element ( URI == nodeElementURIs,
		//						attributes == set ( ( idAttr | nodeIdAttr | aboutAttr )?, propertyAttr* ) )
		//		propertyEltList
		//		end-element()
		//
		// 7.2.13 propertyEltList
		//		ws* ( propertyElt ws* )*
		private void ParseNodeElement (XmpNode parent, XmlNode node)
		{
			if (!node.IsNodeElement ())
				throw new CorruptFileException ("Unexpected node found, invalid RDF?");

			if (node.Is (RDF_NS, SEQ_URI)) {
				parent.Type = XmpNodeType.Seq;
			} else if (node.Is (RDF_NS, ALT_URI)) {
				parent.Type = XmpNodeType.Alt;
			} else if (node.Is (RDF_NS, BAG_URI)) {
				parent.Type = XmpNodeType.Bag;
			} else if (node.Is (RDF_NS, DESCRIPTION_URI)) {
				parent.Type = XmpNodeType.Struct;
			} else {
				throw new Exception ("Unknown nodeelement found! Perhaps an unimplemented collection?");
			}

			foreach (XmlAttribute attr in node.Attributes) {
				if (attr.In (XMLNS_NS))
					continue;
				if (attr.Is (RDF_NS, ID_URI) || attr.Is (RDF_NS, NODE_ID_URI) || attr.Is (RDF_NS, ABOUT_URI))
					continue;
				if (attr.Is (XML_NS, LANG_URI))
					throw new CorruptFileException ("xml:lang is not allowed here!");
				parent.AddChild (new XmpNode (attr.NamespaceURI, attr.LocalName, attr.InnerText));
			}

			foreach (XmlNode child in node.ChildNodes) {
				if (child is XmlWhitespace || child is XmlComment)
					continue;
				ParsePropertyElement (parent, child);
			}
		}
Пример #11
0
        // 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);
        //}
        private void ParseTypeResourcePropertyElement(XmpNode parent, XElement node)
        {
            // TODO: FIX
            //if (!node.IsPropertyElement())
            //    throw new CorruptFileException("Invalid property");

            XmpNode new_node = new XmpNode(node.Name.NamespaceName, node.Name.LocalName);
            new_node.Type = XmpNodeType.Struct;

            foreach (XAttribute attr in node.Attributes())
            {
                if (attr.Is(XML_NS, LANG_URI))
                    new_node.AddQualifier(new XmpNode(XML_NS, LANG_URI, attr.Value));
            }

            foreach (XElement child in node.Elements())
            {
                ParsePropertyElement(new_node, child);
            }

            parent.AddChild(new_node);
        }
Пример #12
0
        // 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);
        //}
        private void ParseResourcePropertyElement(XmpNode parent, XElement node)
        {
            // TODO: FIX
            //if (!node.IsPropertyElement())
            //    throw new CorruptFileException("Invalid property");

            XmpNode new_node = new XmpNode(node.Name.NamespaceName, node.Name.LocalName);
            foreach (XAttribute attr in node.Attributes())
            {
                if (attr.Is(XML_NS, LANG_URI))
                {
                    new_node.AddQualifier(new XmpNode(XML_NS, LANG_URI, attr.Value));
                }
                else if (attr.Is(RDF_NS, ID_URI) || attr.In(XMLNS_NS))
                {
                    continue;
                }

                throw new CorruptFileException(String.Format("Invalid attribute: {0}", attr.Parent.Name.LocalName));
            }

            bool has_xml_children = false;
            foreach (XElement child in node.Elements())
            {
                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);
        }
Пример #13
0
        // 7.2.11 nodeElement
        //        start-element ( URI == nodeElementURIs,
        //                        attributes == set ( ( idAttr | nodeIdAttr | aboutAttr )?, propertyAttr* ) )
        //        propertyEltList
        //        end-element()
        //
        // 7.2.13 propertyEltList
        //        ws* ( propertyElt ws* )*
        //private void ParseNodeElement (XmpNode parent, XmlNode node)
        //{
        //    if (!node.IsNodeElement ())
        //        throw new CorruptFileException ("Unexpected node found, invalid RDF?");
        //    if (node.Is (RDF_NS, SEQ_URI)) {
        //        parent.Type = XmpNodeType.Seq;
        //    } else if (node.Is (RDF_NS, ALT_URI)) {
        //        parent.Type = XmpNodeType.Alt;
        //    } else if (node.Is (RDF_NS, BAG_URI)) {
        //        parent.Type = XmpNodeType.Bag;
        //    } else if (node.Is (RDF_NS, DESCRIPTION_URI)) {
        //        parent.Type = XmpNodeType.Struct;
        //    } else {
        //        throw new Exception ("Unknown nodeelement found! Perhaps an unimplemented collection?");
        //    }
        //    foreach (XmlAttribute attr in node.Attributes) {
        //        if (attr.In (XMLNS_NS))
        //            continue;
        //        if (attr.Is (RDF_NS, ID_URI) || attr.Is (RDF_NS, NODE_ID_URI) || attr.Is (RDF_NS, ABOUT_URI))
        //            continue;
        //        if (attr.Is (XML_NS, LANG_URI))
        //            throw new CorruptFileException ("xml:lang is not allowed here!");
        //        parent.AddChild (new XmpNode (attr.NamespaceURI, attr.LocalName, attr.InnerText));
        //    }
        //    foreach (XmlNode child in node.ChildNodes) {
        //        if (child is XmlWhitespace || child is XmlComment)
        //            continue;
        //        ParsePropertyElement (parent, child);
        //    }
        //}
        private void ParseNodeElement(XmpNode parent, XElement node)
        {
            if (node.Is(RDF_NS, SEQ_URI))
            {
                parent.Type = XmpNodeType.Seq;
            }
            else if (node.Is(RDF_NS, ALT_URI))
            {
                parent.Type = XmpNodeType.Alt;
            }
            else if (node.Is(RDF_NS, BAG_URI))
            {
                parent.Type = XmpNodeType.Bag;
            }
            else if (node.Is(RDF_NS, DESCRIPTION_URI))
            {
                parent.Type = XmpNodeType.Struct;
            }
            else
            {
                throw new Exception("Unknown nodeelement found! Perhaps an unimplemented collection?");
            }

            foreach (XAttribute attr in node.Attributes())
            {
                if (attr.In(XMLNS_NS))
                    continue;
                if (attr.Is(RDF_NS, ID_URI) || attr.Is(RDF_NS, NODE_ID_URI) || attr.Is(RDF_NS, ABOUT_URI))
                    continue;
                if (attr.Is(XML_NS, LANG_URI))
                    throw new CorruptFileException("xml:lang is not allowed here!");
                parent.AddChild(new XmpNode(attr.Name.NamespaceName, attr.Name.LocalName, attr.Value));
            }

            foreach (XElement child in node.Elements())
            {
                ParsePropertyElement(parent, child);
            }
        }
Пример #14
0
 // 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));
 //}
 private void ParseLiteralPropertyElement(XmpNode parent, XElement node)
 {
     // TODO: FIX
     //if (!node.IsPropertyElement())
     //    throw new CorruptFileException("Invalid property");
     parent.AddChild(CreateTextPropertyWithQualifiers(node, node.Value));
 }