public FindChildByName ( string expr ) : |
||
expr | string | child node name to look for |
return |
/// <summary> /// Find or create a child node under a given parent node. If the parent node is no /// Returns the found or created child node. /// </summary> /// <param name="parent"> /// the parent node </param> /// <param name="childName"> /// the node name to find </param> /// <param name="createNodes"> /// flag, if new nodes shall be created. </param> /// <returns> Returns the found or created node or <code>null</code>. </returns> /// <exception cref="XmpException"> Thrown if </exception> internal static XmpNode FindChildNode(XmpNode parent, string childName, bool createNodes) { if (!parent.Options.SchemaNode && !parent.Options.Struct) { if (!parent.Implicit) { throw new XmpException("Named children only allowed for schemas and structs", XmpError.BADXPATH); } if (parent.Options.Array) { throw new XmpException("Named children not allowed for arrays", XmpError.BADXPATH); } if (createNodes) { parent.Options.Struct = true; } } XmpNode childNode = parent.FindChildByName(childName); if (childNode == null && createNodes) { PropertyOptions options = new PropertyOptions(); childNode = new XmpNode(childName, options); childNode.Implicit = true; parent.AddChild(childNode); } Debug.Assert(childNode != null || !createNodes); return(childNode); }
/// <summary> /// Find or create a schema node if <code>createNodes</code> is true. /// </summary> /// <param name="tree"> the root of the xmp tree. </param> /// <param name="namespaceUri"> a namespace </param> /// <param name="suggestedPrefix"> If a prefix is suggested, the namespace is allowed to be registered. </param> /// <param name="createNodes"> a flag indicating if the node shall be created if not found. /// <em>Note:</em> The namespace must be registered prior to this call. /// </param> /// <returns> Returns the schema node if found, <code>null</code> otherwise. /// Note: If <code>createNodes</code> is <code>true</code>, it is <b>always</b> /// returned a valid node. </returns> /// <exception cref="XmpException"> An exception is only thrown if an error occurred, not if a /// node was not found. </exception> internal static XmpNode FindSchemaNode(XmpNode tree, string namespaceUri, string suggestedPrefix, bool createNodes) { Debug.Assert(tree.Parent == null); // make sure that its the root XmpNode schemaNode = tree.FindChildByName(namespaceUri); if (schemaNode == null && createNodes) { PropertyOptions propertyOptions = new PropertyOptions(); propertyOptions.SchemaNode = true; schemaNode = new XmpNode(namespaceUri, propertyOptions); schemaNode.Implicit = true; // only previously registered schema namespaces are allowed in the XMP tree. string prefix = XMPMetaFactory.SchemaRegistry.GetNamespacePrefix(namespaceUri); if (prefix == null) { if (!String.IsNullOrEmpty(suggestedPrefix)) { prefix = XMPMetaFactory.SchemaRegistry.RegisterNamespace(namespaceUri, suggestedPrefix); } else { throw new XmpException("Unregistered schema namespace URI", XmpError.BADSCHEMA); } } schemaNode.Value = prefix; tree.AddChild(schemaNode); } return(schemaNode); }
/// <summary> /// Find or create a child node under a given parent node. If the parent node is no /// Returns the found or created child node. /// </summary> /// <param name="parent"> /// the parent node </param> /// <param name="childName"> /// the node name to find </param> /// <param name="createNodes"> /// flag, if new nodes shall be created. </param> /// <returns> Returns the found or created node or <code>null</code>. </returns> /// <exception cref="XmpException"> Thrown if </exception> internal static XmpNode FindChildNode(XmpNode parent, string childName, bool createNodes) { if (!parent.Options.SchemaNode && !parent.Options.Struct) { if (!parent.Implicit) { throw new XmpException("Named children only allowed for schemas and structs", XmpError.BADXPATH); } if (parent.Options.Array) { throw new XmpException("Named children not allowed for arrays", XmpError.BADXPATH); } if (createNodes) { parent.Options.Struct = true; } } XmpNode childNode = parent.FindChildByName(childName); if (childNode == null && createNodes) { PropertyOptions options = new PropertyOptions(); childNode = new XmpNode(childName, options); childNode.Implicit = true; parent.AddChild(childNode); } Debug.Assert(childNode != null || !createNodes); return childNode; }
/// <summary> /// Find or create a schema node if <code>createNodes</code> is true. /// </summary> /// <param name="tree"> the root of the xmp tree. </param> /// <param name="namespaceUri"> a namespace </param> /// <param name="suggestedPrefix"> If a prefix is suggested, the namespace is allowed to be registered. </param> /// <param name="createNodes"> a flag indicating if the node shall be created if not found. /// <em>Note:</em> The namespace must be registered prior to this call. /// </param> /// <returns> Returns the schema node if found, <code>null</code> otherwise. /// Note: If <code>createNodes</code> is <code>true</code>, it is <b>always</b> /// returned a valid node. </returns> /// <exception cref="XmpException"> An exception is only thrown if an error occurred, not if a /// node was not found. </exception> internal static XmpNode FindSchemaNode(XmpNode tree, string namespaceUri, string suggestedPrefix, bool createNodes) { Debug.Assert(tree.Parent == null); // make sure that its the root XmpNode schemaNode = tree.FindChildByName(namespaceUri); if (schemaNode == null && createNodes) { PropertyOptions propertyOptions = new PropertyOptions(); propertyOptions.SchemaNode = true; schemaNode = new XmpNode(namespaceUri, propertyOptions); schemaNode.Implicit = true; // only previously registered schema namespaces are allowed in the XMP tree. string prefix = XMPMetaFactory.SchemaRegistry.GetNamespacePrefix(namespaceUri); if (prefix == null) { if (!String.IsNullOrEmpty(suggestedPrefix)) { prefix = XMPMetaFactory.SchemaRegistry.RegisterNamespace(namespaceUri, suggestedPrefix); } else { throw new XmpException("Unregistered schema namespace URI", XmpError.BADSCHEMA); } } schemaNode.Value = prefix; tree.AddChild(schemaNode); } return schemaNode; }