473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

User-defined attributes in XMLSchema

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>
Feb 15 '06 #1
4 1395
..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.Sc hemaElement) {
//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" <ge*********@REMOVESPAM.hotmail.com> wrote in message
news:D5**********************************@microsof t.com...
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>

Feb 16 '06 #2
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.Sc hemaElement) {
//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" <ge*********@REMOVESPAM.hotmail.com> wrote in message
news:D5**********************************@microsof t.com...
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>


Feb 16 '06 #3
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.Sc hemaElement) {
//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" <ge*********@REMOVESPAM.hotmail.com> wrote in message
news:D5**********************************@microsof t.com...
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>


Feb 17 '06 #4
Okay, found the solution!

The problem was me ;-)

After referencing the correct schema, Priya's solution
worked perfectly.

Thanks again!

Best regards,

Geir Aamodt

"Geir Aamodt" wrote:
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.Sc hemaElement) {
//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" <ge*********@REMOVESPAM.hotmail.com> wrote in message
news:D5**********************************@microsof t.com...
>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>

Feb 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

60
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm ...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
0
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
1
by: Carlettus | last post by:
Dear All, sorry but I'm not sure if this is the right place to post my problem. I was using the following asp code to create users in Active Directory. Suddenly, and I don't know the reason, users...
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
14
by: chromis | last post by:
Hi, I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.