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); }
static MetadataStore () { Namespaces = new NamespaceManager (); Namespaces.AddNamespace (PhotoshopNS, "photoshop"); Namespaces.AddNamespace (Iptc4xmpCoreNS, "Iptc4xmpCore"); Namespaces.AddNamespace (DcNS, "dc"); Namespaces.AddNamespace (XmpNS, "xmp"); Namespaces.AddNamespace (XmpidqNS, "xmpidq"); Namespaces.AddNamespace (XmpRightsNS, "xmpRights"); Namespaces.AddNamespace (XmpBJNS, "xmpBJ"); Namespaces.AddNamespace (XmpMMNS, "xmpMM"); Namespaces.AddNamespace (ExifNS, "exif"); Namespaces.AddNamespace (TiffNS, "tiff"); Namespaces.AddNamespace (RdfNS, "rdf"); Namespaces.AddNamespace (RdfsNS, "rdfs"); Namespaces.AddNamespace (IViewNS, "mediapro"); Namespaces.AddNamespace (CcNS, "cc"); }
private bool ReadStatement(ParseContext context) { Location loc = context.Location; bool reverse, forgetBNode; Resource subject = ReadResource(context, true, out reverse, out forgetBNode); if (subject == null) { return(false); } if (reverse) { OnError("is...of not allowed on a subject", loc); } if ((object)subject == (object)PrefixResource) { loc = context.Location; string qname = ReadToken(context.source, context) as string; if (qname == null || !qname.EndsWith(":")) { OnError("When using @prefix, the prefix identifier must end with a colon", loc); } loc = context.Location; bool fb2; Resource uri = ReadResource(context, false, out reverse, out fb2); if (uri == null) { OnError("Expecting a URI", loc); } if (reverse) { OnError("is...of not allowed here", loc); } namespaces.AddNamespace(uri.Uri, qname.Substring(0, qname.Length - 1)); loc = context.Location; char punc = ReadPunc(context.source); if (punc != '.') { OnError("Expected a period but found '" + punc + "'", loc); } return(true); } if ((object)subject == (object)KeywordsResource) { context.UsingKeywords = true; context.Keywords = new Hashtable(); while (true) { ReadWhitespace(context.source); if (context.source.Peek() == '.') { context.source.Read(); break; } loc = context.Location; string tok = ReadToken(context.source, context) as string; if (tok == null) { OnError("Expecting keyword names", loc); } context.Keywords[tok] = tok; } return(true); } if ((object)subject == (object)BaseResource) { loc = context.Location; bool fb2; Resource uri = ReadResource(context, false, out reverse, out fb2); if (uri == null || uri.Uri == null) { OnError("Expecting a URI", loc); } if (reverse) { OnError("is...of not allowed here", loc); } BaseUri = uri.Uri; loc = context.Location; char punc = ReadPunc(context.source); if (punc != '.') { OnError("Expected a period but found '" + punc + "'", loc); } return(true); } // It's possible to just assert the presence of an entity // by following the entity with a period, or a } to end // a reified context. if (NextPunc(context.source) == '.') { context.source.Read(); if (forgetBNode) { DoForget(subject, context); } return(true); } if (NextPunc(context.source) == '}') { context.source.Read(); if (forgetBNode) { DoForget(subject, context); } return(false); // end of block } // Read the predicates for this subject. char period = ReadPredicates(subject, context); loc = context.Location; if (period != '.' && period != '}') { OnError("Expected a period but found '" + period + "'", loc); } if (period == '}') { return(false); } if (forgetBNode) { DoForget(subject, context); } return(true); }
public NamespaceManager GetQueryPrefixes() { NamespaceManager ns = new NamespaceManager(); java.util.Map prefixes = ((QueryData)query).getPrefixExpansions(); for (java.util.Iterator i = prefixes.keySet().iterator(); i.hasNext(); ) { string prefix = (string)i.next(); string uri = prefixes.get(prefix).ToString(); // surrounded in < > uri = uri.Substring(1, uri.Length-2); // not sure how to get this directly ns.AddNamespace(uri, prefix); } return ns; }
public static void Main(string[] args) { Opts opts = new Opts(); opts.ProcessArgs(args); if (opts.RemainingArguments.Length != 2 && opts.RemainingArguments.Length != 3) { opts.DoHelp(); return; } string datasource, rootentity, stylesheetfile; if (opts.RemainingArguments.Length == 2) { datasource = opts.RemainingArguments[0]; rootentity = null; stylesheetfile = opts.RemainingArguments[1]; } else { datasource = opts.RemainingArguments[0]; rootentity = opts.RemainingArguments[1]; stylesheetfile = opts.RemainingArguments[2]; } XsltArgumentList xsltargs = new XsltArgumentList(); if (opts.param != null) foreach (string p in opts.param) { int eq = p.IndexOf('='); if (eq == -1) { Console.Error.WriteLine("Param arguments must be name=value."); return; } string n = p.Substring(0, eq); string v = p.Substring(eq+1); xsltargs.AddParam(n, "", v); } XmlDocument sty = new XmlDocument(); sty.PreserveWhitespace = true; sty.Load(stylesheetfile); XslTransform t = new XslTransform(); t.Load(sty, null, null); NamespaceManager nsmgr = new NamespaceManager(); // Scan xmlsn: attributes in the stylesheet node. // For all namespaces of the form assembly://assemblyname/TypeName, load in // the methods of that type as extension functions in that namespace. // And add xmlns declarations to nsmgr. foreach (XmlAttribute a in sty.DocumentElement.Attributes) { if (!a.Name.StartsWith("xmlns:")) continue; nsmgr.AddNamespace(a.Value, a.Name.Substring(6)); System.Uri uri = new System.Uri(a.Value); if (uri.Scheme != "assembly") continue; System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(uri.Host); System.Type ty = assembly.GetType(uri.AbsolutePath.Substring(1)); if (ty == null) { Console.Error.WriteLine("Type not found: " + uri); return; } object obj = ty.GetConstructor(new Type[0]).Invoke(new Type[0]); xsltargs.AddExtensionObject(a.Value, obj); } StatementSource source = Store.CreateForInput(datasource); Store model; if (source is Store) model = (Store)source; else model = new MemoryStore(source); XPathNavigator nav; if (rootentity != null) nav = new XPathSemWebNavigator(rootentity, model, nsmgr); else nav = new XPathSemWebNavigator(model, nsmgr); t.Transform(nav, xsltargs, Console.Out, null); }
/// <summary> /// Maps the namespace with the specified URI to the specified prefix. /// </summary> /// <param name="uri">The URI.</param> /// <param name="prefix">The prefix.</param> public override void AddNamespace(string uri, string prefix) { m_OriginalNamespaceManager.AddNamespace(uri, prefix); }