本文整理汇总了C#中System.Xml.Schema.XmlSchema类的典型用法代码示例。如果您正苦于以下问题:C# XmlSchema类的具体用法?C# XmlSchema怎么用?C# XmlSchema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlSchema类属于System.Xml.Schema命名空间,在下文中一共展示了XmlSchema类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Bug360541
public void Bug360541 ()
{
XmlSchemaComplexType stype = GetStype ();
XmlSchemaElement selem1 = new XmlSchemaElement ();
selem1.Name = "schema";
selem1.SchemaType = stype;
XmlSchema schema = new XmlSchema ();
schema.Items.Add (selem1);
XmlSchemas xs = new XmlSchemas ();
xs.Add (schema);
xs.Find (XmlQualifiedName.Empty, typeof (XmlSchemaElement));
selem1 = new XmlSchemaElement ();
selem1.Name = "schema1";
selem1.SchemaType = stype;
schema = new XmlSchema ();
schema.Items.Add (selem1);
xs = new XmlSchemas ();
xs.Add (schema);
xs.Find (XmlQualifiedName.Empty, typeof (XmlSchemaElement));
}
开发者ID:nobled,项目名称:mono,代码行数:27,代码来源:XmlSchemasTests.cs
示例2: LoadSchema
private void LoadSchema(string schemaUri)
{
//string fullSchemaURI = @"http://local.bbc.co.uk:8081/schemas/" + schemaUri;
//string fullSchemaURI = @"http://dnadev.national.core.bbc.co.uk/bbc.dna/schemas/" + schemaUri;
if (_cachedSchemas.ContainsKey(schemaUri))
{
//Retrieve shema from cache.
_xmlSchema = _cachedSchemas[schemaUri];
}
else
{
//Get Local Path of schema file.
// Make sure that you specify the Schema directory name is Case correct.
using (var iis = IIsInitialise.GetIIsInitialise())
{
String path = iis.GetVDirPath("h2g2UnitTesting", "Schemas");
path = Path.Combine(path, schemaUri);
_xmlSchema = new XmlSchema();
//Uri ourUri = new Uri(fullSchemaURI);
//WebRequest request = WebRequest.Create(ourUri);
//request.Proxy = null;
//WebResponse response = request.GetResponse();
//Read Schema from local path. This allows relative includes within the schema files to be resolved correctly.
_xmlSchema = XmlSchema.Read(new XmlTextReader(path), new ValidationEventHandler(xmlReaderSettingsValidationEventHandler));
}
//Cache it.
_cachedSchemas[schemaUri] = _xmlSchema;
}
}
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:35,代码来源:DnaXmlValidator.cs
示例3: CreateXmlReaderSettings
private static XmlReaderSettings CreateXmlReaderSettings(XmlSchema xmlSchema)
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(xmlSchema);
return settings;
}
开发者ID:SaintLoong,项目名称:UltraNuke_Library,代码行数:7,代码来源:XmlSchemas.cs
示例4: Compile
///<remarks>
/// 1. Content must be present and one of restriction or extention
///</remarks>
internal override int Compile(ValidationEventHandler h, XmlSchema schema)
{
// If this is already compiled this time, simply skip.
if (CompilationId == schema.CompilationId)
return 0;
if(Content == null)
{
error(h, "Content must be present in a simpleContent");
}
else
{
if(Content is XmlSchemaSimpleContentRestriction)
{
XmlSchemaSimpleContentRestriction xscr = (XmlSchemaSimpleContentRestriction) Content;
errorCount += xscr.Compile(h, schema);
}
else if(Content is XmlSchemaSimpleContentExtension)
{
XmlSchemaSimpleContentExtension xsce = (XmlSchemaSimpleContentExtension) Content;
errorCount += xsce.Compile(h, schema);
}
else
error(h,"simpleContent can't have any value other than restriction or extention");
}
XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
this.CompilationId = schema.CompilationId;
return errorCount;
}
开发者ID:nobled,项目名称:mono,代码行数:33,代码来源:XmlSchemaSimpleContent.cs
示例5: CustomizeGeneratedCode
/// <summary>
/// Customizes the generated code to better conform to the NHibernate's coding conventions.
/// </summary>
/// <param name="code">The customizable code DOM.</param>
/// <param name="sourceSchema">The source XML Schema.</param>
protected override void CustomizeGeneratedCode(CodeNamespace code, XmlSchema sourceSchema)
{
new ImproveHbmTypeNamesCommand(code).Execute();
new ImproveEnumFieldsCommand(code).Execute();
// TODO: Rename class fields?
}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:12,代码来源:HbmCodeGenerator.cs
示例6: v2
public void v2()
{
XmlSchemaSet sc = new XmlSchemaSet();
sc.XmlResolver = new XmlUrlResolver();
XmlSchema schema = new XmlSchema();
sc.Add(null, TestData._XsdNoNs);
CError.Compare(sc.Count, 1, "AddCount");
CError.Compare(sc.IsCompiled, false, "AddIsCompiled");
sc.Compile();
CError.Compare(sc.IsCompiled, true, "IsCompiled");
CError.Compare(sc.Count, 1, "Count");
try
{
schema = sc.Add(null, Path.Combine(TestData._Root, "include_v2.xsd"));
}
catch (XmlSchemaException)
{
// no schema should be addded to the set.
CError.Compare(sc.Count, 1, "Count");
CError.Compare(sc.IsCompiled, true, "IsCompiled");
return;
}
Assert.True(false);
}
开发者ID:dotnet,项目名称:corefx,代码行数:26,代码来源:TC_SchemaSet_Includes.cs
示例7: TestSimpleValidation
public void TestSimpleValidation ()
{
string xml = "<root/>";
xvr = PrepareXmlReader (xml);
Assert.AreEqual (ValidationType.Auto, xvr.ValidationType);
XmlSchema schema = new XmlSchema ();
XmlSchemaElement elem = new XmlSchemaElement ();
elem.Name = "root";
schema.Items.Add (elem);
xvr.Schemas.Add (schema);
xvr.Read (); // root
Assert.AreEqual (ValidationType.Auto, xvr.ValidationType);
xvr.Read (); // EOF
xml = "<hoge/>";
xvr = PrepareXmlReader (xml);
xvr.Schemas.Add (schema);
try {
xvr.Read ();
Assert.Fail ("element mismatch is incorrectly allowed");
} catch (XmlSchemaException) {
}
xml = "<hoge xmlns='urn:foo' />";
xvr = PrepareXmlReader (xml);
xvr.Schemas.Add (schema);
try {
xvr.Read ();
Assert.Fail ("Element in different namespace is incorrectly allowed.");
} catch (XmlSchemaException) {
}
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:32,代码来源:XsdValidatingReaderTests.cs
示例8: Add
internal void Add(XmlDocument schemaDoc, XmlSchema schema, string typeName, string namespaceUri)
{
XmlSchemaSimpleType simpleType = schema.SchemaTypes[new XmlQualifiedName(typeName, namespaceUri)] as XmlSchemaSimpleType;
XmlSchemaSimpleTypeRestriction typeRestriction = simpleType.Content as XmlSchemaSimpleTypeRestriction;
XmlSchemaPatternFacet pattern = typeRestriction.Facets[0] as XmlSchemaPatternFacet;
Regex re = new Regex(pattern.Value);
XmlNodeList attributeNameNodes = schemaDoc.SelectNodes("//*[@type='" + typeName + "']/@name");
for (int i = 0; i < attributeNameNodes.Count; i++)
{
string attrName = attributeNameNodes.Item(i).Value;
if (RegexForAttrName[attrName] != null)
{
continue;
}
else
{
RegexForAttrName[attrName] = re;
if (XPathPredicateOfAttributes == null)
{
XPathPredicateOfAttributes = "";
}
else
{
XPathPredicateOfAttributes += " or ";
}
XPathPredicateOfAttributes += "local-name() = '" + attrName + "'";
}
}
}
开发者ID:joeaudette,项目名称:mojoportal,代码行数:30,代码来源:AttributeValueValidator.cs
示例9: ValidateSpecification
public static void ValidateSpecification(XmlElement containingNode, XmlSchema schema)
{
// We must parse the XML to get the schema validation to work. So, we write
// the xml out to a string, and read it back in with Schema Validation enabled
var sw = new StringWriter();
var xmlWriterSettings = new XmlWriterSettings
{
Encoding = Encoding.UTF8,
ConformanceLevel = ConformanceLevel.Fragment,
Indent = false,
NewLineOnAttributes = false,
IndentChars = ""
};
var xmlWriter = XmlWriter.Create(sw, xmlWriterSettings);
foreach (XmlNode node in containingNode.ChildNodes)
node.WriteTo(xmlWriter);
xmlWriter.Close();
var xmlReaderSettings = new XmlReaderSettings
{
ValidationType = ValidationType.Schema,
ConformanceLevel = ConformanceLevel.Fragment,
Schemas = new XmlSchemaSet()
};
xmlReaderSettings.Schemas.Add(schema);
var xmlReader = XmlTextReader.Create(new StringReader(sw.ToString()), xmlReaderSettings);
while (xmlReader.Read()) ;
xmlReader.Close();
}
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:32,代码来源:XmlSpecificationSchema.cs
示例10: Process
/// <summary>Called when extension shall processs generated CodeDOM</summary>
/// <param name="code">Object tree representing generated CodeDOM</param>
/// <param name="schema">Input XML schema</param>
/// <param name="provider">CodeDOM provider (the language)</param>
/// <version version="1.5.3">Added documentation</version>
/// <version version="1.5.3">Parameter <c>Provider</c> renamed to <c>provider</c></version>
public void Process(CodeNamespace code, XmlSchema schema, CodeDomProvider provider)
{
// Copy as we will be adding types.
CodeTypeDeclaration[] types =
new CodeTypeDeclaration[code.Types.Count];
code.Types.CopyTo(types, 0);
foreach (CodeTypeDeclaration type in types) {
if (type.IsClass || type.IsStruct) {
foreach (CodeTypeMember member in type.Members) {
if (member is CodeMemberField && ((CodeMemberField)member).Type.ArrayElementType != null) {
CodeMemberField field = (CodeMemberField)member;
// Change field type to collection.
field.Type = GetCollection(field.Type.ArrayElementType);
field.InitExpression = new CodeObjectCreateExpression(field.Type);
if (field.Name.EndsWith("Field"))
field.Comments.Add(new CodeCommentStatement(string.Format("<summary>Contains value of the <see cref='{0}'/> property</summary>", field.Name.Substring(0, field.Name.Length - "field".Length)), true));
} else if (member is CodeMemberProperty && ((CodeMemberProperty)member).Type.ArrayElementType != null) {
CodeMemberProperty Property = (CodeMemberProperty)member;
Property.Type = GetCollection(Property.Type.ArrayElementType);
Property.HasSet = false;
}
}
}
}
}
开发者ID:wskplho,项目名称:Tools,代码行数:32,代码来源:ArraysToGenericCollections.cs
示例11: addElements
private void addElements(XmlSchema schema, string targetNamespaceUri)
{
debug("adding elements: " + schema.Elements.Count);
debug("adding elements items: " + schema.Items.Count);
foreach (XmlSchemaObject item in schema.Items)
{
var element = item as XmlSchemaElement;
if (element != null && element.SchemaType is XmlSchemaComplexType)
{
processComplexType(targetNamespaceUri, element.SchemaType as XmlSchemaComplexType, element.Name, Elements);
}
}
foreach (XmlSchemaElement element in schema.Elements.Values)
{
if (element.SchemaType is XmlSchemaComplexType)
{
processComplexType(targetNamespaceUri, element.SchemaType as XmlSchemaComplexType, element.Name, Elements);
}
}
debug("Elements Found: " + Elements.Count);
foreach (var elems in Elements)
{
debug("Elem: " + elems.Key + ":" + elems.Value.Name);
debug(string.Join(", ", elems.Value.Properties.Select(_ => _.Name + ":" + _.Type).ToArray()));
}
}
开发者ID:kmcgain,项目名称:WsdlGenerator,代码行数:29,代码来源:XmlTypeExtractor.cs
示例12: GetXml
private string GetXml(XmlSchema schema)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(SerializeObjectToXml(schema));
return @"<?xml version=""1.0"" encoding=""utf-8""?>"
+ xmlDoc.DocumentElement.OuterXml;
}
开发者ID:estelleLeBouler,项目名称:SData-Contracts,代码行数:7,代码来源:GetSchemaImportRequestPerformer.cs
示例13: SchemaObjectInfo
internal SchemaObjectInfo(XmlSchemaType type, XmlSchemaElement element, XmlSchema schema, List<XmlSchemaType> knownTypes)
{
this.type = type;
this.element = element;
this.schema = schema;
this.knownTypes = knownTypes;
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:SchemaHelper.cs
示例14: AddElementForm
internal static void AddElementForm(XmlSchemaElement element, XmlSchema schema)
{
if (schema.ElementFormDefault != XmlSchemaForm.Qualified)
{
element.Form = XmlSchemaForm.Qualified;
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:SchemaHelper.cs
示例15: CreateAbstractBaseSchemaFromMaindocSchema
/// <summary>
/// TODO: Create new XmlSchema instead of DeepCopy
/// </summary>
/// <param name="templateSchema">Arbitrary maindoc schema used as a template for our new base class schema</param>
/// <param name="sharedElementCount">Number of elements that shoud be copied over to the new base class schema complex type</param>
/// <returns></returns>
private static XmlSchema CreateAbstractBaseSchemaFromMaindocSchema(XmlSchema templateSchema, int sharedElementCount)
{
XmlSchema abstractBaseSchema = DeepCopy(templateSchema);
var abstractBaseElement = abstractBaseSchema.Items.OfType<XmlSchemaElement>().Single(); // Single. There can only be one
var abstractBaseComplexType = abstractBaseSchema.Items.OfType<XmlSchemaComplexType>().Single(); // Christopher Lambert again
// overwrite template props
abstractBaseSchema.TargetNamespace = abstractBaseSchema.TargetNamespace.Replace(abstractBaseElement.Name, Constants.abstractBaseSchemaName);
abstractBaseSchema.Namespaces.Add("", abstractBaseSchema.TargetNamespace);
abstractBaseSchema.SourceUri = templateSchema.SourceUri.Replace(abstractBaseElement.Name, Constants.abstractBaseSchemaName);
abstractBaseComplexType.IsAbstract = true;
abstractBaseComplexType.Annotation.Items.Clear();
XmlSchemaDocumentation doc = new XmlSchemaDocumentation();
var nodeCreaterDoc = new XmlDocument();
doc.Markup = new XmlNode[] { nodeCreaterDoc.CreateTextNode("This is a custom generated class that holds all the props/fields common to all UBL maindocs."),
nodeCreaterDoc.CreateTextNode("You won't find a matching xsd file where it originates from.") };
abstractBaseComplexType.Annotation.Items.Add(doc);
abstractBaseComplexType.Name = Constants.abstractBaseSchemaComplexTypeName;
// remove non-shared tailing elements.
XmlSchemaObjectCollection elementCollection = (abstractBaseComplexType.Particle as XmlSchemaSequence).Items;
while (sharedElementCount < elementCollection.Count) elementCollection.RemoveAt(sharedElementCount);
abstractBaseElement.Name = Constants.abstarctBaseSchemaElementName;
abstractBaseElement.SchemaTypeName = new XmlQualifiedName(Constants.abstractBaseSchemaComplexTypeName, abstractBaseSchema.TargetNamespace);
// Don't need schemaLocation for loaded schemas. Will generate schemasetcompile warnings if not removed
foreach (var baseSchemaImports in abstractBaseSchema.Includes.OfType<XmlSchemaImport>()) baseSchemaImports.SchemaLocation = null;
return abstractBaseSchema;
}
开发者ID:Gammern,项目名称:ubllarsen,代码行数:38,代码来源:UblSchemaInheritanceTools.cs
示例16: ProcessClass
/// <summary>
/// Processes the class.
/// </summary>
/// <param name="codeNamespace">The code namespace.</param>
/// <param name="schema">The input XSD schema.</param>
/// <param name="type">Represents a type declaration for a class, structure, interface, or enumeration</param>
protected override void ProcessClass(CodeNamespace codeNamespace, XmlSchema schema, CodeTypeDeclaration type)
{
this.autoPropertyListField.Clear();
this.fieldListToRemoveField.Clear();
this.fieldWithAssignementInCtorListField.Clear();
// looks for properties that can not become automatic property
CodeConstructor ctor = null;
foreach (CodeTypeMember member in type.Members)
{
if (member is CodeConstructor)
ctor = member as CodeConstructor;
}
if (ctor != null)
{
foreach (var statement in ctor.Statements)
{
var codeAssignStatement = statement as CodeAssignStatement;
if (codeAssignStatement == null) continue;
var code = codeAssignStatement.Left as CodeFieldReferenceExpression;
if (code != null)
{
this.fieldWithAssignementInCtorListField.Add(code.FieldName);
}
}
}
base.ProcessClass(codeNamespace, schema, type);
// generate automatic properties
this.GenerateAutomaticProperties(type);
}
开发者ID:flonou,项目名称:xsd2code,代码行数:39,代码来源:Net30Extension.cs
示例17: CreateSimpletypeLength
private void CreateSimpletypeLength(string length, string minLength, string maxLength, bool expected) {
passed = true;
XmlSchema schema = new XmlSchema();
XmlSchemaSimpleType testType = new XmlSchemaSimpleType();
testType.Name = "TestType";
XmlSchemaSimpleTypeRestriction testTypeRestriction = new XmlSchemaSimpleTypeRestriction();
testTypeRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
if (length != "-") {
XmlSchemaLengthFacet _length = new XmlSchemaLengthFacet();
_length.Value = length;
testTypeRestriction.Facets.Add(_length);
}
if (minLength != "-") {
XmlSchemaMinLengthFacet _minLength = new XmlSchemaMinLengthFacet();
_minLength.Value = minLength;
testTypeRestriction.Facets.Add(_minLength);
}
if (maxLength != "-") {
XmlSchemaMaxLengthFacet _maxLength = new XmlSchemaMaxLengthFacet();
_maxLength.Value = maxLength;
testTypeRestriction.Facets.Add(_maxLength);
}
testType.Content = testTypeRestriction;
schema.Items.Add(testType);
schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
Assert.IsTrue (expected == passed, (passed ? "Test passed, should have failed" : "Test failed, should have passed") + ": " + length + " " + minLength + " " + maxLength);
}
开发者ID:nobled,项目名称:mono,代码行数:34,代码来源:XmlSchemaLengthFacetTests.cs
示例18: extractElements
public static List<XmlSchemaElement> extractElements(XmlSchema schema)
{
List<XmlSchemaElement> elements = new List<XmlSchemaElement>();
foreach (object item in schema.Elements)
{
if (item is DictionaryEntry)
{
DictionaryEntry entry = (DictionaryEntry)item;
XmlSchemaElement element = entry.Value as XmlSchemaElement;
if (element != null)
{
elements.Add(element);
}
}
}
foreach (object item in schema.Items)
{
if (item is XmlSchemaElement)
{
XmlSchemaElement element = item as XmlSchemaElement;
if( !elements.Exists(el => el == element ))
elements.Add(element);
}
}
return elements;
}
开发者ID:UtrsSoftware,项目名称:ATMLWorkBench,代码行数:27,代码来源:XsdUtils.cs
示例19: Compile
internal override int Compile(ValidationEventHandler h, XmlSchema schema)
{
// If this is already compiled this time, simply skip.
if (CompilationId == schema.CompilationId)
return 0;
XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);
CompileOccurence (h, schema);
if (Items.Count == 0)
this.warn (h, "Empty choice is unsatisfiable if minOccurs not equals to 0");
foreach(XmlSchemaObject obj in Items)
{
if(obj is XmlSchemaElement ||
obj is XmlSchemaGroupRef ||
obj is XmlSchemaChoice ||
obj is XmlSchemaSequence ||
obj is XmlSchemaAny)
{
errorCount += obj.Compile(h,schema);
}
else
error(h, "Invalid schema object was specified in the particles of the choice model group.");
}
this.CompilationId = schema.CompilationId;
return errorCount;
}
开发者ID:nobled,项目名称:mono,代码行数:28,代码来源:XmlSchemaChoice.cs
示例20: JumpToDoesNothingWhenFileNameIsEmptyString
public void JumpToDoesNothingWhenFileNameIsEmptyString()
{
XmlSchema schemaObject = new XmlSchema();
schemaObject.SourceUri = String.Empty;
DerivedXmlSchemaObjectLocation location = new DerivedXmlSchemaObjectLocation(schemaObject);
Assert.IsFalse(location.IsDerivedJumpToFilePositionMethodCalled);
}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:7,代码来源:SchemaObjectLocationJumpToTests.cs
注:本文中的System.Xml.Schema.XmlSchema类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论