Exemplo n.º 1
0
        private static void AddIdentity(XName name)
        {
            var i = new Identity {
                XmlName    = name,
                JsonName   = name.ToJsonId(),
                ProperName = name.ToProperName(),
                Index      = null
            };

            if (Context.Property(name.LocalName) == null)
            {
                string type = null;
                if (name.Namespace == Namespace.Swid)
                {
                    var element = Schema.Swidtag.XPathSelectElement($@"//xs:attribute[@name=""{name.LocalName}""]", Schema.NamespaceManager);
                    if (element != null)
                    {
                        type = XmlExtensions.GetAttribute(element, "type");

                        if (!type.StartsWith("xs:"))
                        {
                            type = "swid:" + type;
                        }
                    }
                }

                Context.Add(name.LocalName, new JObject {
                    // {"@id", Namespace.Declarations[name.Namespace] + ":" + name.LocalName},
                    { "@id", $"{name.Namespace.NamespaceName}#{name.LocalName}" },
                    { "@type", type ?? "xs:string" }
                });

                Context.Add($"{Namespace.Declarations[name.Namespace]}:{name.LocalName}", new JObject {
                    // {"@id", Namespace.Declarations[name.Namespace] + ":" + name.LocalName},
                    { "@id", $"{name.Namespace.NamespaceName}#{name.LocalName}" },
                    { "@type", type ?? "xs:string" }
                });
            }

            if (!_viaJsonName.ContainsKey(i.JsonName))
            {
                _viaJsonName.Add(i.JsonName, i);
            }
            if (!_viaJsonName.ContainsKey(i.ProperName))
            {
                _viaJsonName.Add(i.ProperName, i);
            }
            if (!_viaXname.ContainsKey(i.XmlName))
            {
                _viaXname.Add(i.XmlName, i);
            }
        }
Exemplo n.º 2
0
        private static string LookupType(XName name)
        {
            string type = null;

            if (name.Namespace == Namespace.Swid)
            {
                var element = Schema.Swidtag.XPathSelectElement($@"//xs:attribute[@name=""{name.LocalName}""]", Schema.NamespaceManager);
                if (element != null)
                {
                    type = XmlExtensions.GetAttribute(element, "type");

                    if (type == "xs:anyURI")
                    {
                        type = "@id";
                    }

                    if (!type.StartsWith("xs:"))
                    {
                        type = "swid:" + type;
                    }
                }
            }
            return(type ?? "xs:string");
        }