Re: User-defined attributes in XMLSchema
- From: "Geir Aamodt" <geir_aamodt@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 17 Feb 2006 00:35:27 -0800
A follow up on this one:
I will really appreciate if someone could test this scenario/code and let me
know if they succeded to find the attribute in the schema as described below.
Best regards,
Geir Aamodt
"Geir Aamodt" wrote:
Thanks Priya,.
just what type of logic I was looking for.
But I'm not able to make it work, when inside the IsSearchableElement
method, the "annotatedSchemaObject.UnhandledAttributes" object is
always null, thus not giving me info about the search:able attribute.
Best regards,
Geir
"Priya Lakshminarayanan" wrote:
..NET XmlSchema Object Model, the search:able attribute will be stored in the
element's UnhandledAttributes array.
While validating an xml file against the schema in .NET 2.0, you can access
the schema information through the SchemaInfo property on the reader as
shown below in the code sample:
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(null, "schemaSample.xsd");
XmlReader validatingReader = XmlReader.Create("myxml.xml", settings);
while(validatingReader.Read()) {
if (validatingReader.NodeType == Element) {
IsSearchableElement(validatingReader.SchemaInfo.SchemaElement) {
//do search:able processing here
}
}
}
private bool IsSearchableElement(XmlSchemaAnnotated annotatedSchemaObject) {
if (annotatedSchemaObject.UnhandledAttributes != null) {
foreach(XmlAttribute att in annotated.UnhandledAttributes) {
if (att.LocalName == "able" && att.NamespaceURI == "SearchNs") {
return true;
}
}
}
return false;
}
Thanks,
Priya
"Geir Aamodt" <geir_aamodt@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D5B582EE-515A-4B78-9493-75114560BB8A@xxxxxxxxxxxxxxxx
I have an xml schema and an xml file. When parsing the xml file I would
like
to perform operations on elements marked in the schema with the
"search:able"
attribute. See sample files below.
Any tips/tricks on how to achieve this?
----------------------XML Schema sample----------------------
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:search="http://www.test.com/test">
<xs:element name="Customers">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerID" type="xs:unsignedByte" search:able="ID"/>
<xs:element name="FirstName" type="xs:string" search:able="Y"/>
<xs:element name="LastName" type="xs:string" search:able="N"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
----------------------XML File sample----------------------
<?xml version="1.0" encoding="utf-8" ?>
<Customers>
<Customer>
<CustomerID>1</CustomerID>
<FirstName>Geir</FirstName>
<LastName>Aamodt</LastName>
</Customer>
<Customer>
<CustomerID>2</CustomerID>
<FirstName>Test</FirstName>
<LastName>Testing</LastName>
</Customer>
</Customers>
- Follow-Ups:
- Re: User-defined attributes in XMLSchema
- From: Geir Aamodt
- Re: User-defined attributes in XMLSchema
- References:
- Re: User-defined attributes in XMLSchema
- From: Priya Lakshminarayanan
- Re: User-defined attributes in XMLSchema
- From: Geir Aamodt
- Re: User-defined attributes in XMLSchema
- Prev by Date: RE: .Net statement efficiency
- Next by Date: Re: User-defined attributes in XMLSchema
- Previous by thread: Re: User-defined attributes in XMLSchema
- Next by thread: Re: User-defined attributes in XMLSchema
- Index(es):
Relevant Pages
|
Loading