本文介绍了查找XML元素的注解在其关联的架构定义的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个XML类型,校舍地址,在一个模式中定义的:I have an xml type, USAddress, defined in a schema:<xsd:element name="MyUSAddress" type="USAddress"/><xsd:complexType name="USAddress"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="street" type="xsd:string"> <xsd:annotation> <xsd:appinfo>Special Metadata</xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="city" type="xsd:string"/> <xsd:element name="state" type="xsd:string"> <xsd:annotation> <xsd:appinfo>Special Metadata</xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="zip" type="xsd:decimal"/> </xsd:sequence></xsd:complexType>和数据实例文档中的XML元素:And an XML element in a data instance document:<MyUSAddress> <name>Robert Smith</name> <street>8 Oak Avenue</street> <city>Old Town</city> <state>PA</state> <zip>95819</zip></MyUSAddress>本模式和实例数据不会在编译时已知,因此所有的分析过程是动态的。此架构的简单仅用于示例的目的。真正的模式将更为复杂。This schema and instance data are not known at compile time, so all analysis is done dynamically. The simplicity of this schema is only for example purposes. Real schemas will be more complex.假设我有加载到System.Xml.Schema.XmlSchema架构,因为我访问的每个节点我的实例XML文档中,的如何才能得到相关的架构元素,并阅读其APPINFO注释?的 Assuming I have the schema loaded into an System.Xml.Schema.XmlSchema, as I visit each node in my instance xml document, how can I get the associated schema element and read its appinfo annotation?推荐答案使用 XMLReader.SchemaInfo财产而你在的节点。然后看看在SchemaType.Annotation.Items。Use the XMLReader.SchemaInfo property while you're at the node. Then look in SchemaType.Annotation.Items.请注意,你的元素/注释嵌套是不完全正确的,但我认为这只是作为简化的无意的副作用。 Note, your element/annotation nesting is not quite right, but I assume that's only as an unintentional side-effect of the simplification. 这篇关于查找XML元素的注解在其关联的架构定义的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 11:58