Пример #1
0
        public void XMPParser_ParseDocument_ListElements()
        {
            PsdLayerConfigs playerConfig = PsdParser.ParseXMP(xmpString);

            Assert.True(playerConfig.HasLayerConfig(13));
            Assert.True(playerConfig.HasLayerConfig(14));
            Assert.True(playerConfig.HasLayerConfig(45));
        }
Пример #2
0
        public static PsdLayerConfigs ParseXMP(string xmpString)
        {
            var result = new PsdLayerConfigs();
            var xmp    = XDocument.Parse(xmpString);

            XElement configRoot = xmp.Descendants(_aguguNamespace + ConfigRootTag).FirstOrDefault();

            if (configRoot == null)
            {
                return(result);
            }

            XElement layersConfigRoot = configRoot.Descendants(_aguguNamespace + LayersRootTag).FirstOrDefault();

            if (layersConfigRoot == null)
            {
                return(result);
            }

            XElement bag = layersConfigRoot.Element(_rdfNamespace + BagTag);

            if (bag == null)
            {
                return(result);
            }

            var layerItems = bag.Elements();

            foreach (XElement listItem in layerItems)
            {
                XElement idElement = listItem.Element(_aguguNamespace + IdTag);
                if (idElement == null)
                {
                    continue;
                }

                int layerId            = Int32.Parse(idElement.Value);
                var propertyDictionary = new Dictionary <string, string>();

                XElement propertiesRoot = listItem.Element(_aguguNamespace + PropertiesTag);
                if (propertiesRoot == null)
                {
                    continue;
                }

                foreach (XElement layerProperty in propertiesRoot.Elements())
                {
                    string propertyName  = layerProperty.Name.LocalName;
                    string propertyValue = layerProperty.Value;

                    propertyDictionary.Add(propertyName, propertyValue);
                }

                result.SetLayerConfig(layerId, propertyDictionary);
            }

            return(result);
        }