private String GenerateUriRef(RdfXmlWriterContext context, Uri u, UriRefType type, out UriRefType outType) { String uriref, qname; if (context.NamespaceMap.ReduceToQName(u.ToString(), out qname) && RdfXmlSpecsHelper.IsValidQName(qname)) { //Reduced to QName OK uriref = qname; outType = UriRefType.QName; } else { //Just use the Uri uriref = u.ToString(); outType = UriRefType.Uri; } //Convert to a Uri Ref from a QName if required if (outType == UriRefType.QName && type == UriRefType.UriRef) { if (uriref.Contains(':') && !uriref.StartsWith(":")) { String prefix = uriref.Substring(0, uriref.IndexOf(':')); if (context.UseDtd && context.NamespaceMap.GetNestingLevel(prefix) == 0) { //Must have Use DTD enabled //Can only use entities for non-temporary Namespaces as Temporary Namespaces won't have Entities defined uriref = "&" + uriref.Replace(':', ';'); outType = UriRefType.UriRef; } else { uriref = context.NamespaceMap.GetNamespaceUri(prefix).ToString() + uriref.Substring(uriref.IndexOf(':') + 1); outType = UriRefType.Uri; } } else { if (context.NamespaceMap.HasNamespace(String.Empty)) { uriref = context.NamespaceMap.GetNamespaceUri(String.Empty).ToString() + uriref.Substring(1); outType = UriRefType.Uri; } else { String baseUri = context.Graph.BaseUri.ToString(); if (!baseUri.EndsWith("#")) { baseUri += "#"; } uriref = baseUri + uriref; outType = UriRefType.Uri; } } //outType = UriRefType.UriRef; } return(uriref); }
private String GenerateUriRef(RdfXmlWriterContext context, IUriNode u, UriRefType type, List <String> tempNamespaceIDs, out UriRefType outType) { String uriref, qname; if (context.Graph.NamespaceMap.ReduceToQName(u.Uri.ToString(), out qname)) { //Reduced to QName OK uriref = qname; outType = UriRefType.QName; } else { //Just use the Uri uriref = u.Uri.ToString(); outType = UriRefType.Uri; } //Convert to a Uri Ref from a QName if required if (outType == UriRefType.QName && type == UriRefType.UriRef) { if (uriref.Contains(':') && !uriref.StartsWith(":")) { String prefix = uriref.Substring(0, uriref.IndexOf(':')); if (context.UseDtd && !tempNamespaceIDs.Contains(prefix)) { //Must be using a DTD to use references of this form //Can only use entities for non-temporary Namespaces as Temporary Namespaces won't have Entities defined uriref = "&" + uriref.Replace(':', ';'); } else { uriref = context.Graph.NamespaceMap.GetNamespaceUri(prefix).ToString() + uriref.Substring(uriref.IndexOf(':') + 1); } } else { if (context.Graph.NamespaceMap.HasNamespace(String.Empty)) { uriref = context.Graph.NamespaceMap.GetNamespaceUri(String.Empty).ToString() + uriref.Substring(1); } else { String baseUri = context.Graph.BaseUri.ToString(); if (!baseUri.EndsWith("#")) { baseUri += "#"; } uriref = baseUri + uriref; } } outType = UriRefType.UriRef; } return(uriref); }
private String GenerateUriRef(RdfXmlWriterContext context, Uri u, UriRefType type, out UriRefType outType) { String uriref, qname; if (context.NamespaceMap.ReduceToQName(u.ToString(), out qname)) { //Reduced to QName OK uriref = qname; outType = UriRefType.QName; } else { //Just use the Uri uriref = u.ToString(); outType = UriRefType.Uri; } //Convert to a Uri Ref from a QName if required if (outType == UriRefType.QName && type == UriRefType.UriRef) { if (uriref.Contains(':') && !uriref.StartsWith(":")) { String prefix = uriref.Substring(0, uriref.IndexOf(':')); if (context.UseDtd && context.NamespaceMap.GetNestingLevel(prefix) == 0) { //Muse have used a DTD to generate this style of URI Reference //Can only use entities for non-temporary Namespaces as Temporary Namespaces won't have Entities defined uriref = "&" + uriref.Replace(':', ';'); outType = UriRefType.UriRef; } else { uriref = context.NamespaceMap.GetNamespaceUri(prefix).ToString() + uriref.Substring(uriref.IndexOf(':') + 1); outType = UriRefType.Uri; } } else { if (context.NamespaceMap.HasNamespace(String.Empty)) { uriref = context.NamespaceMap.GetNamespaceUri(String.Empty).ToString() + uriref.Substring(1); outType = UriRefType.Uri; } else { String baseUri = context.Graph.BaseUri.ToString(); if (!baseUri.EndsWith("#")) baseUri += "#"; uriref = baseUri + uriref; outType = UriRefType.Uri; } } } return uriref; }
private String GenerateUriRef(RdfXmlWriterContext context, IUriNode u, UriRefType type, List<String> tempNamespaceIDs, out UriRefType outType) { String uriref, qname; if (context.Graph.NamespaceMap.ReduceToQName(u.Uri.ToString(), out qname) && RdfXmlSpecsHelper.IsValidQName(qname)) { //Reduced to QName OK uriref = qname; outType = UriRefType.QName; } else { //Just use the Uri uriref = u.Uri.ToString(); outType = UriRefType.Uri; } //Convert to a Uri Ref from a QName if required if (outType == UriRefType.QName && type == UriRefType.UriRef) { if (uriref.Contains(':') && !uriref.StartsWith(":")) { String prefix = uriref.Substring(0, uriref.IndexOf(':')); if (context.UseDtd && !tempNamespaceIDs.Contains(prefix)) { //Must be using a DTD to use references of this form //Can only use entities for non-temporary Namespaces as Temporary Namespaces won't have Entities defined uriref = "&" + uriref.Replace(':', ';'); } else { uriref = context.Graph.NamespaceMap.GetNamespaceUri(prefix).ToString() + uriref.Substring(uriref.IndexOf(':') + 1); } } else { if (context.Graph.NamespaceMap.HasNamespace(String.Empty)) { uriref = context.Graph.NamespaceMap.GetNamespaceUri(String.Empty).ToString() + uriref.Substring(1); } else { String baseUri = context.Graph.BaseUri.ToString(); if (!baseUri.EndsWith("#")) baseUri += "#"; uriref = baseUri + uriref; } } outType = UriRefType.UriRef; } return uriref; }