本文整理汇总了C#中System.Xml.Linq.XElement.GetPrefixOfNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.GetPrefixOfNamespace方法的具体用法?C# XElement.GetPrefixOfNamespace怎么用?C# XElement.GetPrefixOfNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.GetPrefixOfNamespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AtomException
/// <summary>
/// Creates a new atom exception instance.
/// </summary>
/// <param name="message">The exception message.</param>
/// <param name="xml">The XML element that cannot be parsed.</param>
/// <param name="innerException">The inner exception.</param>
public AtomException(string message, XElement xml, Exception innerException)
: base(message, innerException)
{
this.elementPrefixName = xml.GetPrefixOfNamespace(xml.Name.NamespaceName);
this.elementLocalName = xml.Name.LocalName;
this.xml = xml.ToString(SaveOptions.None);
}
示例2: Atom
/// <summary>
/// Creates a new atom instance.
/// </summary>
/// <param name="xmlPrefix">The XML prefix.</param>
/// <param name="xmlName">The XML name.</param>
/// <param name="element">The XML element.</param>
protected Atom(string xmlPrefix, string xmlName, XElement element)
{
// Check the XML element name.
if (!element.HasName(xmlPrefix, xmlName))
{
bool b = element.HasName(xmlPrefix, xmlName);
throw new AtomException("XML element name mismatch. Current name is \'{0}:{1}\'. Expected name is \'{2}:{3}\'".FormatWith(
element.GetPrefixOfNamespace(element.Name.Namespace), element.Name.LocalName, xmlPrefix, xmlName), element);
}
}
示例3: ToString
public static string ToString(this XamlContext ctx, XElement elem, XName name) {
var sb = new StringBuilder();
if (name.Namespace != elem.GetDefaultNamespace() &&
name.Namespace != elem.Name.Namespace &&
!string.IsNullOrEmpty(name.Namespace.NamespaceName)) {
sb.Append(elem.GetPrefixOfNamespace(name.Namespace));
sb.Append(':');
}
sb.Append(name.LocalName);
return sb.ToString();
}
示例4: AnalyzeElement
void AnalyzeElement(XamlContext txt, XElement elem)
{
foreach (var i in elem.Attributes())
if (i.Name.NamespaceName == "http://www.w3.org/2000/xmlns/")
txt.namespaces[i.Name.LocalName] = ParseXmlNs(i.Value, txt);
else if (i.Name.LocalName == "xmlns")
txt.namespaces[""] = ParseXmlNs(i.Value, txt);
XamlName name = XamlName.Parse(elem.Name, txt);
name.Xmlns = elem.GetPrefixOfNamespace(name.Xmlns);
if (name.TypeDef == null)
Logger._Log("> Could not resolve '" + elem.Name.ToString() + "'!");
else if (Assemblies.Contains(name.TypeDef.Module.Assembly))
{
IXmlLineInfo li = elem as IXmlLineInfo;
string line = txt.lines[li.LineNumber - 1];
int end = line.IndexOf(' ', li.LinePosition - 1);
if (end == -1)
end = line.IndexOf('>', li.LinePosition - 1);
string str = line.Substring(li.LinePosition - 1, end - li.LinePosition + 1);
var r = new XamlNameReference() { Name = name };
txt.refers.Add(new XamlRef()
{
lineNum = li.LineNumber - 1,
index = li.LinePosition - 1,
length = end - li.LinePosition + 1,
name = name,
refer = r
});
((name.TypeDef as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(r);
}
foreach (var i in elem.Attributes())
if (i.Name.NamespaceName != "http://www.w3.org/2000/xmlns/" &&
i.Name.LocalName != "xmlns")
AnalyzePropertyAttr(name.TypeDef, txt, i);
foreach (var i in elem.Elements())
{
if (i.Name.LocalName.Contains("."))
AnalyzePropertyElem(name.TypeDef, txt, i);
else
AnalyzeElement(txt, i);
}
}
示例5: FillXmlns
// unlike other XmlWriters the callers must set xmlns
// attribute to overwrite prefix.
void FillXmlns (XElement el, string prefix, XNamespace xns)
{
if (xns == XNamespace.Xmlns)
// do nothing for xmlns attributes
return;
if (xns == XNamespace.None)
if (el.GetPrefixOfNamespace (xns) != prefix)
el.SetAttributeValue (prefix == String.Empty ? XNamespace.None.GetName ("xmlns") : XNamespace.Xmlns.GetName (prefix), xns.NamespaceName);
else if (el.GetDefaultNamespace () != XNamespace.None)
el.SetAttributeValue (XNamespace.None.GetName ("xmlns"), xns.NamespaceName);
}
示例6: AnalyzePropertyElem
void AnalyzePropertyElem(TypeDefinition typeDef, XamlContext txt, XElement elem)
{
XamlPropertyName name = XamlPropertyName.Parse(typeDef, elem.Name, txt);
name.Xmlns = elem.GetPrefixOfNamespace(name.Xmlns);
var prop = ResolveProperty(name.TypeDef, name.PropertyName);
if (prop != null && Assemblies.Contains(prop.DeclaringType.Module.Assembly))
{
IXmlLineInfo li = elem as IXmlLineInfo;
string line = txt.lines[li.LineNumber - 1];
int end = line.IndexOf('>', li.LinePosition - 1);
string str = line.Substring(li.LinePosition - 1, end - li.LinePosition + 1);
var r = new XamlPropertyNameReference() { Name = name };
txt.refers.Add(new XamlRef()
{
lineNum = li.LineNumber - 1,
index = li.LinePosition - 1,
length = end - li.LinePosition + 1,
name = name,
refer = r
});
((prop as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(r);
}
foreach (var i in elem.Elements())
{
if (i.Name.LocalName.Contains("."))
AnalyzePropertyElem(name.TypeDef, txt, i);
else
AnalyzeElement(txt, i);
}
}
示例7: CopyExtendedPropertiesToSsdlElement
internal static void CopyExtendedPropertiesToSsdlElement(MetadataItem metadataItem, XContainer xContainer)
{
foreach (var extendedProperty in metadataItem.MetadataProperties.Where(mp => mp.PropertyKind == PropertyKind.Extended))
{
var exPropertyElement = extendedProperty.Value as XElement;
if (exPropertyElement != null)
{
// find the CopyToSSDL attribute - if it exists it can be in any EDMX namespace
var copyToSSDLAttribute = exPropertyElement.Attributes().FirstOrDefault(
attr => attr.Name.LocalName.Equals("CopyToSSDL", StringComparison.Ordinal)
&& SchemaManager.GetEDMXNamespaceNames().Contains(attr.Name.NamespaceName));
if (copyToSSDLAttribute != null)
{
if ((bool?)copyToSSDLAttribute == true)
{
// CopyToSsdl is true, so let's copy this extended property
var exAttributeNamespace = copyToSSDLAttribute.Name.Namespace;
var newExPropertyElement = new XElement(exPropertyElement);
var newCopyToSsdlAttribute = newExPropertyElement.Attribute(exAttributeNamespace + "CopyToSSDL");
newCopyToSsdlAttribute.Remove();
var namespacePrefix = newExPropertyElement.GetPrefixOfNamespace(exAttributeNamespace);
if (namespacePrefix != null)
{
var xmlnsEdmxAttr = newExPropertyElement.Attribute(XNamespace.Xmlns + namespacePrefix);
if (xmlnsEdmxAttr != null)
{
xmlnsEdmxAttr.Remove();
}
}
xContainer.Add(newExPropertyElement);
}
}
}
}
}
示例8: Rdf_NodeElementAttrs
/// <summary>
/// 7.2.7 propertyAttributeURIs
/// anyURI - ( coreSyntaxTerms | rdf:Description | rdf:li | oldTerms )
/// 7.2.11 nodeElement
/// start-element ( URI == nodeElementURIs,
/// attributes == set ( ( idAttr | nodeIdAttr | aboutAttr )?, propertyAttr* ) )
/// propertyEltList
/// end-element()
/// Process the attribute list for an RDF node element.
/// </summary>
/// <remarks>
/// 7.2.7 propertyAttributeURIs
/// anyURI - ( coreSyntaxTerms | rdf:Description | rdf:li | oldTerms )
/// 7.2.11 nodeElement
/// start-element ( URI == nodeElementURIs,
/// attributes == set ( ( idAttr | nodeIdAttr | aboutAttr )?, propertyAttr* ) )
/// propertyEltList
/// end-element()
/// Process the attribute list for an RDF node element. A property attribute URI is
/// anything other than an RDF term. The rdf:ID and rdf:nodeID attributes are simply ignored,
/// as are rdf:about attributes on inner nodes.
/// </remarks>
/// <param name="xmp">the xmp metadata object that is generated</param>
/// <param name="xmpParent">the parent xmp node</param>
/// <param name="xmlNode">the currently processed XML node</param>
/// <param name="isTopLevel">Flag if the node is a top-level node</param>
/// <exception cref="XmpException">thrown on parsing errors</exception>
private static void Rdf_NodeElementAttrs(XmpMeta xmp, XmpNode xmpParent, XElement xmlNode, bool isTopLevel)
{
// Used to detect attributes that are mutually exclusive.
var exclusiveAttrs = 0;
foreach(var attribute in xmlNode.Attributes())
{
// quick hack, ns declarations do not appear in C++
// ignore "ID" without namespace
var prefix = xmlNode.GetPrefixOfNamespace(attribute.Name.Namespace);
if ("xmlns".Equals(prefix) || (prefix == null && "xmlns".Equals(attribute.Name)))
{
continue;
}
var attrTerm = GetRdfTermKind(attribute);
switch (attrTerm)
{
case RdfTerm.Id:
case RdfTerm.NodeId:
case RdfTerm.About:
{
if (exclusiveAttrs > 0)
{
throw new XmpException("Mutally exclusive about, ID, nodeID attributes", XmpErrorCode.BadRdf);
}
exclusiveAttrs++;
if (isTopLevel && (attrTerm == RdfTerm.About))
{
// This is the rdf:about attribute on a top level node. Set
// the XMP tree name if
// it doesn't have a name yet. Make sure this name matches
// the XMP tree name.
if (!string.IsNullOrEmpty(xmpParent.Name))
{
if (!xmpParent.Name.Equals(attribute.Value))
{
throw new XmpException("Mismatched top level rdf:about values", XmpErrorCode.BadXmp);
}
}
else
{
xmpParent.Name = attribute.Value;
}
}
break;
}
case RdfTerm.Other:
{
AddChildNode(xmp, xmpParent, attribute, attribute.Value, isTopLevel);
break;
}
default:
{
throw new XmpException("Invalid nodeElement attribute", XmpErrorCode.BadRdf);
}
}
}
}
示例9: AcceptMoveFromRanges
private static XElement AcceptMoveFromRanges(XElement document)
{
string wordProcessingNamespacePrefix = document.GetPrefixOfNamespace(W.w);
// The following lists contain the elements that are between start/end elements.
List<XElement> startElementTagsInMoveFromRange = new List<XElement>();
List<XElement> endElementTagsInMoveFromRange = new List<XElement>();
// Following are the elements that *may* be in a range that has both start and end
// elements.
Dictionary<string, PotentialInRangeElements> potentialDeletedElements =
new Dictionary<string, PotentialInRangeElements>();
foreach (var tag in DescendantAndSelfTags(document))
{
if (tag.Element.Name == W.moveFromRangeStart)
{
string id = tag.Element.Attribute(W.id).Value;
potentialDeletedElements.Add(id, new PotentialInRangeElements());
continue;
}
if (tag.Element.Name == W.moveFromRangeEnd)
{
string id = tag.Element.Attribute(W.id).Value;
if (potentialDeletedElements.ContainsKey(id))
{
startElementTagsInMoveFromRange.AddRange(
potentialDeletedElements[id].PotentialStartElementTagsInRange);
endElementTagsInMoveFromRange.AddRange(
potentialDeletedElements[id].PotentialEndElementTagsInRange);
potentialDeletedElements.Remove(id);
}
continue;
}
if (potentialDeletedElements.Count > 0)
{
if (tag.TagType == TagTypeEnum.Element &&
(tag.Element.Name != W.moveFromRangeStart &&
tag.Element.Name != W.moveFromRangeEnd))
{
foreach (var id in potentialDeletedElements)
id.Value.PotentialStartElementTagsInRange.Add(tag.Element);
continue;
}
if (tag.TagType == TagTypeEnum.EmptyElement &&
(tag.Element.Name != W.moveFromRangeStart &&
tag.Element.Name != W.moveFromRangeEnd))
{
foreach (var id in potentialDeletedElements)
{
id.Value.PotentialStartElementTagsInRange.Add(tag.Element);
id.Value.PotentialEndElementTagsInRange.Add(tag.Element);
}
continue;
}
if (tag.TagType == TagTypeEnum.EndElement &&
(tag.Element.Name != W.moveFromRangeStart &&
tag.Element.Name != W.moveFromRangeEnd))
{
foreach (var id in potentialDeletedElements)
id.Value.PotentialEndElementTagsInRange.Add(tag.Element);
continue;
}
}
}
var moveFromElementsToDelete = startElementTagsInMoveFromRange
.Intersect(endElementTagsInMoveFromRange)
.ToArray();
if (moveFromElementsToDelete.Count() > 0)
return (XElement)AcceptMoveFromRangesTransform(
document, moveFromElementsToDelete);
return document;
}
示例10: ElementGetPrefixOfNamespace
/// <summary>
/// Tests XElement.GetPrefixOfNamespace().
/// </summary>
/// <param name="contextValue"></param>
/// <returns></returns>
//[Variation(Desc = "ElementGetPrefixOfNamespace")]
public void ElementGetPrefixOfNamespace()
{
try
{
new XElement("foo").GetPrefixOfNamespace(null);
Validate.ExpectedThrow(typeof(ArgumentNullException));
}
catch (Exception ex)
{
Validate.Catch(ex, typeof(ArgumentNullException));
}
XNamespace ns = XNamespace.Get("http://test");
XElement e = new XElement(ns + "foo");
string prefix = e.GetPrefixOfNamespace(ns);
Validate.IsNull(prefix);
prefix = e.GetPrefixOfNamespace(XNamespace.Xmlns);
Validate.String(prefix, "xmlns");
prefix = e.GetPrefixOfNamespace(XNamespace.Xml);
Validate.String(prefix, "xml");
XElement parent = new XElement("parent", e);
parent.SetAttributeValue("{http://www.w3.org/2000/xmlns/}myns", ns);
prefix = e.GetPrefixOfNamespace(ns);
Validate.String(prefix, "myns");
e = XElement.Parse("<foo:element xmlns:foo='http://xxx'></foo:element>");
prefix = e.GetPrefixOfNamespace("http://xxx");
Validate.String(prefix, "foo");
e = XElement.Parse("<foo:element xmlns:foo='http://foo' xmlns:bar='http://bar'><bar:element /></foo:element>");
prefix = e.GetPrefixOfNamespace("http://foo");
Validate.String(prefix, "foo");
prefix = e.Element(XName.Get("{http://bar}element")).GetPrefixOfNamespace("http://foo");
Validate.String(prefix, "foo");
prefix = e.Element(XName.Get("{http://bar}element")).GetPrefixOfNamespace("http://bar");
Validate.String(prefix, "bar");
}
示例11: AddChildNode
/// <summary>Adds a child node.</summary>
/// <param name="xmp">the xmp metadata object that is generated</param>
/// <param name="xmpParent">the parent xmp node</param>
/// <param name="xmlNode">the currently processed XML node</param>
/// <param name="value">Node value</param>
/// <param name="isTopLevel">Flag if the node is a top-level node</param>
/// <returns>Returns the newly created child node.</returns>
/// <exception cref="XmpException">thrown on parsing errors</exception>
private static XmpNode AddChildNode(XmpMeta xmp, XmpNode xmpParent, XElement xmlNode, string value, bool isTopLevel)
{
return AddChildNode(xmp, xmpParent, xmlNode.Name, xmlNode.GetPrefixOfNamespace(xmlNode.Name.Namespace), value, isTopLevel);
}
示例12: Rdf_EmptyPropertyElement
/// <summary>
/// 7.2.21 emptyPropertyElt
/// start-element ( URI == propertyElementURIs,
/// attributes == set (
/// idAttr?, ( resourceAttr | nodeIdAttr )?, propertyAttr* ) )
/// end-element()
/// <ns:Prop1/> <!-- a simple property with an empty value -->
/// <ns:Prop2 rdf:resource="http: *www.adobe.com/"/> <!-- a URI value -->
/// <ns:Prop3 rdf:value="..." ns:Qual="..."/> <!-- a simple qualified property -->
/// <ns:Prop4 ns:Field1="..." ns:Field2="..."/> <!-- a struct with simple fields -->
/// An emptyPropertyElt is an element with no contained content, just a possibly empty set of
/// attributes.
/// </summary>
/// <remarks>
/// 7.2.21 emptyPropertyElt
/// start-element ( URI == propertyElementURIs,
/// attributes == set (
/// idAttr?, ( resourceAttr | nodeIdAttr )?, propertyAttr* ) )
/// end-element()
/// <ns:Prop1/> <!-- a simple property with an empty value -->
/// <ns:Prop2 rdf:resource="http: *www.adobe.com/"/> <!-- a URI value -->
/// <ns:Prop3 rdf:value="..." ns:Qual="..."/> <!-- a simple qualified property -->
/// <ns:Prop4 ns:Field1="..." ns:Field2="..."/> <!-- a struct with simple fields -->
/// An emptyPropertyElt is an element with no contained content, just a possibly empty set of
/// attributes. An emptyPropertyElt can represent three special cases of simple XMP properties: a
/// simple property with an empty value (ns:Prop1), a simple property whose value is a URI
/// (ns:Prop2), or a simple property with simple qualifiers (ns:Prop3).
/// An emptyPropertyElt can also represent an XMP struct whose fields are all simple and
/// unqualified (ns:Prop4).
/// It is an error to use both rdf:value and rdf:resource - that can lead to invalid RDF in the
/// verbose form written using a literalPropertyElt.
/// The XMP mapping for an emptyPropertyElt is a bit different from generic RDF, partly for
/// design reasons and partly for historical reasons. The XMP mapping rules are:
/// <list type="bullet">
/// <item> If there is an rdf:value attribute then this is a simple property
/// with a text value.
/// All other attributes are qualifiers.</item>
/// <item> If there is an rdf:resource attribute then this is a simple property
/// with a URI value.
/// All other attributes are qualifiers.</item>
/// <item> If there are no attributes other than xml:lang, rdf:ID, or rdf:nodeID
/// then this is a simple
/// property with an empty value.</item>
/// <item> Otherwise this is a struct, the attributes other than xml:lang, rdf:ID,
/// or rdf:nodeID are fields.</item>
/// </list>
/// </remarks>
/// <param name="xmp">the xmp metadata object that is generated</param>
/// <param name="xmpParent">the parent xmp node</param>
/// <param name="xmlNode">the currently processed XML node</param>
/// <param name="isTopLevel">Flag if the node is a top-level node</param>
/// <exception cref="XmpException">thrown on parsing errors</exception>
private static void Rdf_EmptyPropertyElement(XmpMeta xmp, XmpNode xmpParent, XElement xmlNode, bool isTopLevel)
{
var hasPropertyAttrs = false;
var hasResourceAttr = false;
var hasNodeIdAttr = false;
var hasValueAttr = false;
XAttribute valueNode = null;
// ! Can come from rdf:value or rdf:resource.
if (!(xmlNode.FirstNode == null))
{
throw new XmpException("Nested content not allowed with rdf:resource or property attributes", XmpErrorCode.BadRdf);
}
// First figure out what XMP this maps to and remember the XML node for a simple value.
foreach (var attribute in xmlNode.Attributes())
{
var prefix = xmlNode.GetPrefixOfNamespace(attribute.Name.Namespace);
if ("xmlns".Equals(prefix) || (prefix == null && "xmlns".Equals(attribute.Name)))
{
continue;
}
var attrTerm = GetRdfTermKind(attribute);
switch (attrTerm)
{
case RdfTerm.Id:
{
// Nothing to do.
break;
}
case RdfTerm.Resource:
{
if (hasNodeIdAttr)
{
throw new XmpException("Empty property element can't have both rdf:resource and rdf:nodeID", XmpErrorCode.BadRdf);
}
if (hasValueAttr)
{
throw new XmpException("Empty property element can't have both rdf:value and rdf:resource", XmpErrorCode.BadXmp);
}
hasResourceAttr = true;
if (!hasValueAttr)
{
valueNode = attribute;
}
break;
}
case RdfTerm.NodeId:
//.........这里部分代码省略.........
示例13: Rdf_ParseTypeResourcePropertyElement
/// <summary>
/// 7.2.18 parseTypeResourcePropertyElt
/// start-element ( URI == propertyElementURIs,
/// attributes == set ( idAttr?, parseResource ) )
/// propertyEltList
/// end-element()
/// Add a new struct node with a qualifier for the possible rdf:ID attribute.
/// </summary>
/// <remarks>
/// 7.2.18 parseTypeResourcePropertyElt
/// start-element ( URI == propertyElementURIs,
/// attributes == set ( idAttr?, parseResource ) )
/// propertyEltList
/// end-element()
/// Add a new struct node with a qualifier for the possible rdf:ID attribute.
/// Then process the XML child nodes to get the struct fields.
/// </remarks>
/// <param name="xmp">the xmp metadata object that is generated</param>
/// <param name="xmpParent">the parent xmp node</param>
/// <param name="xmlNode">the currently processed XML node</param>
/// <param name="isTopLevel">Flag if the node is a top-level node</param>
/// <exception cref="XmpException">thrown on parsing errors</exception>
private static void Rdf_ParseTypeResourcePropertyElement(XmpMeta xmp, XmpNode xmpParent, XElement xmlNode, bool isTopLevel)
{
var newStruct = AddChildNode(xmp, xmpParent, xmlNode, string.Empty, isTopLevel);
newStruct.Options.IsStruct = true;
foreach (var attribute in xmlNode.Attributes())
{
var prefix = xmlNode.GetPrefixOfNamespace(attribute.Name.Namespace);
if ("xmlns".Equals(prefix) || (prefix == null && "xmlns".Equals(attribute.Name)))
{
continue;
}
var attrLocal = attribute.Name.LocalName;
var attrNs = attribute.Name.NamespaceName;
if (XmpConstants.XmlLang.Equals("xml:" + attribute.Name.LocalName))
{
AddQualifierNode(newStruct, XmpConstants.XmlLang, attribute.Value);
}
else
{
if (XmpConstants.NsRdf.Equals(attrNs) && ("ID".Equals(attrLocal) || "parseType".Equals(attrLocal)))
{
continue;
}
// The caller ensured the value is "Resource".
// Ignore all rdf:ID attributes.
throw new XmpException("Invalid attribute for ParseTypeResource property element", XmpErrorCode.BadRdf);
}
}
Rdf_PropertyElementList(xmp, newStruct, xmlNode, false);
if (newStruct.HasValueChild)
{
FixupQualifiedNode(newStruct);
}
}
示例14: Rdf_LiteralPropertyElement
/// <summary>
/// 7.2.16 literalPropertyElt
/// start-element ( URI == propertyElementURIs,
/// attributes == set ( idAttr?, datatypeAttr?) )
/// text()
/// end-element()
/// Add a leaf node with the text value and qualifiers for the attributes.
/// </summary>
/// <param name="xmp">the xmp metadata object that is generated</param>
/// <param name="xmpParent">the parent xmp node</param>
/// <param name="xmlNode">the currently processed XML node</param>
/// <param name="isTopLevel">Flag if the node is a top-level node</param>
/// <exception cref="XmpException">thrown on parsing errors</exception>
private static void Rdf_LiteralPropertyElement(XmpMeta xmp, XmpNode xmpParent, XElement xmlNode, bool isTopLevel)
{
var newChild = AddChildNode(xmp, xmpParent, xmlNode, null, isTopLevel);
foreach (var attribute in xmlNode.Attributes())
{
var prefix = xmlNode.GetPrefixOfNamespace(attribute.Name.Namespace);
if ("xmlns".Equals(prefix) || (prefix == null && "xmlns".Equals(attribute.Name)))
{
continue;
}
var attrNs = attribute.Name.NamespaceName;
var attrLocal = attribute.Name.LocalName;
if (XmpConstants.XmlLang.Equals("xml:" + attribute.Name.LocalName))
{
AddQualifierNode(newChild, XmpConstants.XmlLang, attribute.Value);
}
else
{
if (XmpConstants.NsRdf.Equals(attrNs) && ("ID".Equals(attrLocal) || "datatype".Equals(attrLocal)))
{
continue;
}
// Ignore all rdf:ID and rdf:datatype attributes.
throw new XmpException("Invalid attribute for literal property element", XmpErrorCode.BadRdf);
}
}
var textValue = string.Empty;
foreach(var child in xmlNode.Nodes())
{
if (child.NodeType == System.Xml.XmlNodeType.Text)
{
textValue += ((XText)child).Value;
}
else
{
throw new XmpException("Invalid child of literal property element", XmpErrorCode.BadRdf);
}
}
newChild.Value = textValue;
}
示例15: Rdf_ResourcePropertyElement
/// <summary>
/// 7.2.15 resourcePropertyElt
/// start-element ( URI == propertyElementURIs, attributes == set ( idAttr? ) )
/// ws* nodeElement ws
/// end-element()
/// This handles structs using an rdf:Description node,
/// arrays using rdf:Bag/Seq/Alt, and typedNodes.
/// </summary>
/// <remarks>
/// 7.2.15 resourcePropertyElt
/// start-element ( URI == propertyElementURIs, attributes == set ( idAttr? ) )
/// ws* nodeElement ws
/// end-element()
/// This handles structs using an rdf:Description node,
/// arrays using rdf:Bag/Seq/Alt, and typedNodes. It also catches and cleans up qualified
/// properties written with rdf:Description and rdf:value.
/// </remarks>
/// <param name="xmp">the xmp metadata object that is generated</param>
/// <param name="xmpParent">the parent xmp node</param>
/// <param name="xmlNode">the currently processed XML node</param>
/// <param name="isTopLevel">Flag if the node is a top-level node</param>
/// <exception cref="XmpException">thrown on parsing errors</exception>
private static void Rdf_ResourcePropertyElement(XmpMeta xmp, XmpNode xmpParent, XElement xmlNode, bool isTopLevel)
{
if (isTopLevel && "iX:changes".Equals(xmlNode.Name))
{
// Strip old "punchcard" chaff which has on the prefix "iX:".
return;
}
var newCompound = AddChildNode(xmp, xmpParent, xmlNode, string.Empty, isTopLevel);
// walk through the attributes
foreach(var attribute in xmlNode.Attributes())
{
var prefix = xmlNode.GetPrefixOfNamespace(attribute.Name.Namespace);
if ("xmlns".Equals(prefix) || (prefix == null && "xmlns".Equals(attribute.Name)))
{
continue;
}
var attrLocal = attribute.Name.LocalName;
var attrNs = attribute.Name.NamespaceName;
if (XmpConstants.XmlLang.Equals("xml:" + attribute.Name.LocalName))
{
AddQualifierNode(newCompound, XmpConstants.XmlLang, attribute.Value);
}
else
{
if ("ID".Equals(attrLocal) && XmpConstants.NsRdf.Equals(attrNs))
{
continue;
}
// Ignore all rdf:ID attributes.
throw new XmpException("Invalid attribute for resource property element", XmpErrorCode.BadRdf);
}
}
// walk through the children
var found = false;
foreach(var currChild in xmlNode.Nodes())
{
if (!IsWhitespaceNode(currChild))
{
if (currChild.NodeType == System.Xml.XmlNodeType.Element && !found)
{
var currChildElem = (XElement)currChild;
var isRdf = XmpConstants.NsRdf.Equals(currChildElem.Name.NamespaceName);
var childLocal = currChildElem.Name.LocalName;
if (isRdf && "Bag".Equals(childLocal))
{
newCompound.Options.IsArray = true;
}
else if (isRdf && "Seq".Equals(childLocal))
{
newCompound.Options.IsArray = true;
newCompound.Options.IsArrayOrdered = true;
}
else if (isRdf && "Alt".Equals(childLocal))
{
newCompound.Options.IsArray = true;
newCompound.Options.IsArrayOrdered = true;
newCompound.Options.IsArrayAlternate = true;
}
else
{
newCompound.Options.IsStruct = true;
if (!isRdf && !"Description".Equals(childLocal))
{
var typeName = currChildElem.Name.NamespaceName;
if (typeName == null)
{
throw new XmpException("All XML elements must be in a namespace", XmpErrorCode.BadXmp);
}
typeName += ':' + childLocal;
AddQualifierNode(newCompound, "rdf:type", typeName);
}
}
Rdf_NodeElement(xmp, newCompound, currChildElem, false);
if (newCompound.HasValueChild)
FixupQualifiedNode(newCompound);
else if (newCompound.Options.IsArrayAlternate)
XmpNodeUtils.DetectAltText(newCompound);
//.........这里部分代码省略.........