Re: User-defined attributes in XMLSchema



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>



.



Relevant Pages

  • Re: help with reading xml file
    ... You have too many levels in your XML file. ... Columnnames then are simply names of the columns, ... This is the case without a schema. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: same application on multiple schemas
    ... As for the "comparison" with Sql Server, it was not intended to ask ... why Oracle does "not" support sql server behaviour:) I know oracle (I ... For every customer that will use our application, ... will use schema "SchemaA" ...
    (comp.databases.oracle.server)
  • Re: same application on multiple schemas
    ... As for the "comparison" with Sql Server, it was not intended to ask ... why Oracle does "not" support sql server behaviour:) I know oracle (I ... For every customer that will use our application, ... will use schema "SchemaA" ...
    (comp.databases.oracle.server)
  • Re: Creating Ruby Classes from XSD?
    ... to the data specification, you want it to be EXACTLY the same. ... XSD schema has the ability to specify ... Suppose the addresses are in a customer ... the Street2 field isn't very useful, ...
    (comp.lang.ruby)
  • Re: same application on multiple schemas
    ... As for the "comparison" with Sql Server, it was not intended to ask ... why Oracle does "not" support sql server behaviour:) I know oracle (I ... For every customer that will use our application, ... will use schema "SchemaA" ...
    (comp.databases.oracle.server)

Loading