本文整理汇总了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;
}