本文整理匯總了C#中System.Xml.XmlResolver.GetEntity方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlResolver.GetEntity方法的具體用法?C# XmlResolver.GetEntity怎麽用?C# XmlResolver.GetEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlResolver
的用法示例。
在下文中一共展示了XmlResolver.GetEntity方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ProcessExternal
void ProcessExternal (ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaExternal ext, XmlSchemaSet col)
{
if (ext == null) {
error (handler, String.Format ("Object of Type {0} is not valid in Includes Property of XmlSchema", ext.GetType().Name));
return;
}
// The only case we want to handle where the SchemaLocation is null is if the external is an import.
XmlSchemaImport import = ext as XmlSchemaImport;
if (ext.SchemaLocation == null && import == null)
return;
XmlSchema includedSchema = null;
if (ext.SchemaLocation != null)
{
Stream stream = null;
string url = null;
if (resolver != null) {
url = GetResolvedUri (resolver, ext.SchemaLocation);
if (handledUris.Contains (url))
// This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur.
return;
handledUris.Add (url, url);
try {
stream = resolver.GetEntity (new Uri (url), null, typeof (Stream)) as Stream;
} catch (Exception) {
// LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch.
warn (handler, "Could not resolve schema location URI: " + url);
stream = null;
}
}
// Process redefinition children in advance.
XmlSchemaRedefine redefine = ext as XmlSchemaRedefine;
if (redefine != null) {
for (int j = 0; j < redefine.Items.Count; j++) {
XmlSchemaObject redefinedObj = redefine.Items [j];
redefinedObj.isRedefinedComponent = true;
redefinedObj.isRedefineChild = true;
if (redefinedObj is XmlSchemaType ||
redefinedObj is XmlSchemaGroup ||
redefinedObj is XmlSchemaAttributeGroup)
compilationItems.Add (redefinedObj);
else
error (handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup.");
}
}
if (stream == null) {
// It is missing schema components.
missedSubComponents = true;
return;
} else {
XmlTextReader xtr = null;
try {
xtr = new XmlTextReader (url, stream, nameTable);
includedSchema = XmlSchema.Read (xtr, handler);
} finally {
if (xtr != null)
xtr.Close ();
}
includedSchema.schemas = schemas;
}
includedSchema.SetParent ();
ext.Schema = includedSchema;
}
// Set - actual - target namespace for the included schema * before compilation*.
if (import != null) {
if (ext.Schema == null && ext.SchemaLocation == null) {
// if a schema location wasn't specified, check the other schemas we have to see if one of those
// is a match.
foreach(XmlSchema schema in col.Schemas())
{
if (schema.TargetNamespace == import.Namespace)
{
includedSchema = schema;
includedSchema.schemas = schemas;
includedSchema.SetParent ();
ext.Schema = includedSchema;
break;
}
}
// handle case where target namespace doesn't exist in schema collection - i.e can't find it at all
if (includedSchema == null)
return;
} else if (includedSchema != null) {
if (TargetNamespace == includedSchema.TargetNamespace) {
error (handler, "Target namespace must be different from that of included schema.");
return;
} else if (includedSchema.TargetNamespace != import.Namespace) {
error (handler, "Attribute namespace and its importing schema's target namespace must be the same.");
return;
}
}
} else if (includedSchema != null) {
if (TargetNamespace == null &&
includedSchema.TargetNamespace != null) {
error (handler, "Target namespace is required to include a schema which has its own target namespace");
return;
//.........這裏部分代碼省略.........
示例2: LoadDoc
public static XPathDocument LoadDoc(Uri uri, XmlResolver resolver){
var s = resolver.GetEntity(uri, "", typeof (Stream)) as Stream;
return GetDoc(s);
}
示例3: PrepareContent
public long PrepareContent(XPathItemFactory itemFactory, XmlResolver resolver)
{
XPathItem item = this.Content;
if (item != null) {
XmlQualifiedName method = _Method ?? GetMethodFromMediaType(this.MediaType, this.Method);
this.contentStream = new MemoryStream();
Serialize(this.contentStream, itemFactory, method);
this.contentStream.Position = 0;
} else if (this.Src != null) {
if (resolver == null) {
throw new ArgumentNullException("resolver");
}
Stream source = resolver.GetEntity(this.Src, null, typeof(Stream)) as Stream;
if (source != null) {
if (source.CanSeek) {
this.contentStream = source;
} else {
this.contentStream = new MemoryStream();
source.CopyTo(this.contentStream);
this.contentStream.Position = 0;
source.Dispose();
}
} else {
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Could not resolve {0}.", this.Src.AbsoluteUri));
}
}
return (this.contentStream != null) ?
this.contentStream.Length
: 0;
}