Ejemplo n.º 1
0
        private static IXmpMeta ParseXmlDoc(XDocument document, ParseOptions options)
        {
            // sort node Attributes to match Java DocumentBuilder (attribute order isn't supposed to matter but DocumentBuilder does some sorting)
            // namespace declarations come first, and then all are sorted in prefix:localname order
            foreach (var node in document.Descendants().Where(d => d.Attributes().Count() > 1))
            {
                var orderedattribs = node.Attributes()
                                     .OrderBy(n => !n.IsNamespaceDeclaration)
                                     .ThenBy(t => node.GetPrefixOfNamespace(t.Name.Namespace), StringComparer.Ordinal)
                                     .ThenBy(s => s.Name.LocalName, StringComparer.Ordinal);
                node.ReplaceAttributes(orderedattribs);
            }

            var result = FindRootNode(document.Nodes(), options.RequireXmpMeta, new object[3]);

            if (result == null || result[1] != XmpRdf)
            {
                // no appropriate root node found, return empty metadata object
                return(new XmpMeta());
            }

            var xmp = ParseRdf.Parse((XElement)result[0]);

            xmp.SetPacketHeader((string)result[2]);

            // Check if the XMP object shall be normalized
            return(!options.OmitNormalization
                ? XmpNormalizer.Process(xmp, options)
                : xmp);
        }
Ejemplo n.º 2
0
 /// <exception cref="XmpException"/>
 public void Normalize(ParseOptions options)
 {
     if (options == null)
     {
         options = new ParseOptions();
     }
     XmpNormalizer.Process(this, options);
 }
Ejemplo n.º 3
0
 private static IXmpMeta ParseXmlDoc(XmlDocument document, ParseOptions options)
 {
     object[] result;
     if (FindRootNode(document, options.RequireXmpMeta, out result) && result[1] == XmpRdf)
     {
         var xmp = ParseRdf.Parse((XmlNode)result[0]);
         xmp.SetPacketHeader((string)result[2]);
         // Check if the XMP object shall be normalized
         if (!options.OmitNormalization)
         {
             return(XmpNormalizer.Process(xmp, options));
         }
         return(xmp);
     }
     // no appropriate root node found, return empty metadata object
     return(new XmpMeta());
 }