Beispiel #1
0
 void AddDefaultNamespaces()
 {
     foreach (var item in DefaultNamespaces)
     {
         Namespaces.AddNamespace(item.Key, item.Value);
     }
 }
Beispiel #2
0
        private Resource ResolveQName(string str, ParseContext context, Location loc)
        {
            int    colon  = str.IndexOf(":");
            string prefix = str.Substring(0, colon);

            if (prefix == "_")
            {
                Resource ret = (Resource)context.anonymous[str];
                if (ret == null)
                {
                    ret = new BNode(str.Substring(colon + 1));
                    context.anonymous[str] = ret;
                }
                return(ret);
            }
            else if (prefix == "" && context.namespaces.GetNamespace(prefix) == null)
            {
                return(GetResource(context, (BaseUri == null ? "#" : BaseUri) + str.Substring(colon + 1)));
            }
            else
            {
                string ns = context.namespaces.GetNamespace(prefix);
                if (ns == null)
                {
                    OnError("Prefix is undefined: " + str, loc);
                }
                if (prefix != "")
                {
                    Namespaces.AddNamespace(ns, prefix);
                }
                return(GetResource(context, ns + str.Substring(colon + 1)));
            }
        }
Beispiel #3
0
        private void LoadNamespaces()
        {
            // Move to the document element and load any namespace
            // declarations on the node.

            while (xml.Read())
            {
                if (xml.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (xml.MoveToFirstAttribute())
                {
                    do
                    {
                        if (xml.Prefix == "xmlns")
                        {
                            Namespaces.AddNamespace(xml.Value, xml.LocalName);
                        }
                    } while (xml.MoveToNextAttribute());
                    xml.MoveToElement();
                }
                break;
            }
        }
            public string SetNamespace(string ns)
            {
                string?prefix = _namespaces.LookupPrefix(ns);

                if (prefix == null || prefix.Length == 0)
                {
                    prefix = "xg" + (_nextPrefix++).ToString(NumberFormatInfo.InvariantInfo);
                    Namespaces.AddNamespace(prefix, ns);
                }
                return(prefix);
            }
Beispiel #5
0
            public override void Add(Statement stmt)
            {
                string predicate = stmt.Predicate.Uri;
                string prefix;
                string localname;

                // Fill in the namespaces with nice prefixes
                if (MetadataStore.Namespaces.Normalize(predicate, out prefix, out localname))
                {
                    if (prefix != null)
                    {
                        Namespaces.AddNamespace(predicate.Remove(predicate.Length - localname.Length, localname.Length), prefix);
                    }
                }
                base.Add(stmt);
            }
        /// <summary>
        /// Trims out the SPARQL preamble (BASE and PREFIX definitions) from the command text
        /// </summary>
        /// <remarks>
        /// This is done so the instance can be directly merged into another SparqlParameterizedString through the Append methods
        /// </remarks>
        private String TrimPreamble(String value)
        {
            int commandStart = 0;

            foreach (Match preambleItem in PreambleCapturePattern.Matches(value))
            {
                if (preambleItem.Groups[1].Value.ToUpper().StartsWith("BASE"))
                {
                    BaseUri = UriFactory.Create(preambleItem.Groups[3].Value);
                    Namespaces.AddNamespace("", BaseUri);
                }
                else
                {
                    Namespaces.AddNamespace(preambleItem.Groups[2].Value, UriFactory.Create(preambleItem.Groups[3].Value));
                }
                commandStart = preambleItem.Index + preambleItem.Length;
            }
            return(value.Substring(commandStart));
        }
Beispiel #7
0
        private string CurNode()
        {
            if (xml.NamespaceURI == "")
            {
                OnWarning("Element node must be qualified (" + xml.Name + ")");
            }
            if (xml.Prefix != "")
            {
                Namespaces.AddNamespace(xml.NamespaceURI, xml.Prefix);
            }

            // This probably isn't quite right, but compensates
            // for a corresponding hash issue in XmlWriter.
            if (xml.NamespaceURI == "" && BaseUri == null)
            {
                return("#" + xml.LocalName);
            }

            return(CheckUri(xml.NamespaceURI + xml.LocalName));
        }
Beispiel #8
0
        private bool ParsePropertyAttributes(Entity entity)
        {
            bool foundAttrs = false;

            if (!xml.MoveToFirstAttribute())
            {
                return(false);
            }
            do
            {
                // Propery attributes in the default namespace
                // should be ignored.
                if (xml.NamespaceURI == "")
                {
                    continue;
                }

                string curnode = CurNode();

                // rdf:type is interpreted with an entity object,
                // not a literal object.
                if (curnode == NS.RDF + "type")
                {
                    storage.Add(new Statement(entity, rdfType, (Entity)xml.Value, Meta));
                    foundAttrs = true;
                    continue;
                }

                // Properties which are not recognized as property
                // attributes and should be ignored.
                if (IsRestrictedName(curnode))
                {
                    continue;
                }
                if (IsDeprecatedName(curnode))
                {
                    OnError(xml.Name + " is deprecated");
                }

                // Properties which are invalid as attributes.
                if (curnode == NS.RDF + "li")
                {
                    OnError("rdf:li is not a valid attribute");
                }
                if (curnode == NS.RDF + "aboutEach" || curnode == NS.RDF + "aboutEachPrefix")
                {
                    OnError("rdf:aboutEach has been removed from the RDF spec");
                }

                // Unrecognized attributes in the xml namespace should be ignored.
                if (xml.Prefix == "xml")
                {
                    continue;
                }
                if (xml.Prefix == "xmlns")
                {
                    continue;
                }
                if (curnode == "http://www.w3.org/2000/xmlns/xmlns")
                {
                    continue;
                }

                // This is a literal property attribute.
                string lang = xml.XmlLang != "" ? xml.XmlLang : null;
                storage.Add(new Statement(entity, curnode,
                                          new Literal(xml.Value, lang, null), Meta));
                Namespaces.AddNamespace(xml.NamespaceURI, xml.Prefix);
                foundAttrs = true;
            } while (xml.MoveToNextAttribute());

            xml.MoveToElement();

            return(foundAttrs);
        }
Beispiel #9
0
 public void AddDomainNamespace(string prefix, string namespaceUri)
 {
     Namespaces.AddNamespace(prefix, namespaceUri);
 }
Beispiel #10
0
 public void SetTypedDomainNamespace(string prefix, string namespaceUri)
 {
     Namespaces.AddNamespace(prefix, namespaceUri);
     TypedDomainNamespace = namespaceUri;
 }
Beispiel #11
0
 public void SetMetricNamespace(string prefix, string namespaceUri)
 {
     Namespaces.AddNamespace(prefix, namespaceUri);
     FactNamespace = namespaceUri;
 }
Beispiel #12
0
 public void SetDimensionNamespace(string prefix, string namespaceUri)
 {
     Namespaces.AddNamespace(prefix, namespaceUri);
     DimensionNamespace = namespaceUri;
 }