private void Start()
        {
            if (initialized)
            {
                return;
            }
            initialized = true;

            if (doc == null)
            {
                doc = new XmlDocument();
            }

            doc.AppendChild(doc.CreateXmlDeclaration("1.0", null, null));

            string rdfprefix = ns.GetPrefix(NS.RDF);

            if (rdfprefix == null)
            {
                if (ns.GetNamespace("rdf") == null)
                {
                    rdfprefix = "rdf";
                    ns.AddNamespace(NS.RDF, "rdf");
                }
            }

            XmlElement root = doc.CreateElement(rdfprefix + ":RDF", NS.RDF);

            foreach (string prefix in ns.GetPrefixes())
            {
                root.SetAttribute("xmlns:" + prefix, ns.GetNamespace(prefix));
            }

            if (BaseUri != null)
            {
                root.SetAttribute("xml:base", BaseUri);
            }

            doc.AppendChild(root);
        }
Esempio n. 2
0
        public virtual string GetNamespace(string prefix)
        {
            string ret = (string)btoa[prefix];

            if (ret != null)
            {
                return(ret);
            }
            if (parent != null)
            {
                return(parent.GetNamespace(prefix));
            }
            return(null);
        }
        private void WriteStatement2(string subj, string pred, string obj)
        {
            closed = false;

            // Write the prefix directives at the beginning.
            if (!hasWritten && ns != null && !(Format == Formats.NTriples))
            {
                foreach (string prefix in ns.GetPrefixes())
                {
                    writer.Write("@prefix ");
                    writer.Write(prefix);
                    writer.Write(": <");
                    writer.Write(ns.GetNamespace(prefix));
                    writer.Write("> .\n");
                }
            }

            // Repeated subject.
            if (lastSubject != null && lastSubject == subj && !(Format == Formats.NTriples))
            {
                // Repeated predicate too.
                if (lastPredicate != null && lastPredicate == pred)
                {
                    writer.Write(",\n\t\t");
                    WriteThing(obj);

                    // Just a repeated subject.
                }
                else
                {
                    writer.Write(";\n\t");
                    WriteThing(pred);
                    WriteThing(obj);
                    lastPredicate = pred;
                }

                // The subject became the object.  Abbreviate with
                // is...of notation (Notation3 format only).
            }
            else if (lastSubject != null && lastSubject == obj && (Format == Formats.Notation3))
            {
                writer.Write(";\n\tis ");
                WriteThing(pred);
                writer.Write("of ");
                WriteThing(subj);
                lastPredicate = null;

                // Start a new statement.
            }
            else
            {
                if (hasWritten)
                {
                    writer.Write(".\n");
                }

                WriteThing(subj);
                WriteThing(pred);
                WriteThing(obj);

                lastSubject   = subj;
                lastPredicate = pred;
            }

            hasWritten = true;
        }
Esempio n. 4
0
 /// <summary>
 /// Gets the namespace with the specified prefix.
 /// </summary>
 /// <param name="prefix">The prefix.</param>
 /// <returns>The namespace</returns>
 public override string GetNamespace(string prefix)
 {
     return(m_OriginalNamespaceManager.GetNamespace(prefix));
 }