本文整理汇总了C#中iTextSharp.xmp.impl.XmpNode.FindChildByName方法的典型用法代码示例。如果您正苦于以下问题:C# XmpNode.FindChildByName方法的具体用法?C# XmpNode.FindChildByName怎么用?C# XmpNode.FindChildByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.xmp.impl.XmpNode
的用法示例。
在下文中一共展示了XmpNode.FindChildByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindChildNode
/// <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;
}
示例2: FindSchemaNode
/// <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;
}