By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,235 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

How to add non-native attribute to XmlSchema in .NET

P: n/a
I am building an XML Schema with the SOM in .NET and would like to add
a non-native attribute to one of my elements. Does anyone know how to
do this? (Whithout rendering the schema to an XmlDocument to do it.)

Thanks!
Eric
Nov 11 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Eric wrote:
I am building an XML Schema with the SOM in .NET and would like to add
a non-native attribute to one of my elements. Does anyone know how to
do this? (Whithout rendering the schema to an XmlDocument to do it.)


What do you mean "non-native"?
If that means non-schema attributes (some proprietary attribute say on
xs:element) you can add it by filling UnhandledAttributes collection.

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2

P: n/a
On Fri, 19 Sep 2003 23:02:12 +0300, Oleg Tkachenko
<oleg@NO_SPAM_PLEASEtkachenko.com> wrote:
Eric wrote:
I am building an XML Schema with the SOM in .NET and would like to add
a non-native attribute to one of my elements. Does anyone know how to
do this? (Whithout rendering the schema to an XmlDocument to do it.)


What do you mean "non-native"?
If that means non-schema attributes (some proprietary attribute say on
xs:element) you can add it by filling UnhandledAttributes collection.


Oleg, thanks for the reonse.

Yes, I mean non-schema attributes. UnhandledAttributes is an array of
XmlAttribute objects. This looks like it is meant to be used when
reading a schema file. How would I use it in building the schema file?
Nov 11 '05 #3

P: n/a
Eric Farr wrote:
Yes, I mean non-schema attributes. UnhandledAttributes is an array of
XmlAttribute objects. This looks like it is meant to be used when
reading a schema file. How would I use it in building the schema file?


Hmm, really. I've got no better idea than using dummy XmlDocument:
XmlSchema schema = new XmlSchema();
XmlSchemaElement elem = new XmlSchemaElement();
elem.Name = "foo";
elem.SchemaTypeName = new XmlQualifiedName("string",
"http://www.w3.org/2001/XMLSchema");
XmlDocument dummyDoc = new XmlDocument();
XmlAttribute attr = dummyDoc.CreateAttribute("myns:blah",
"http://myns.com");
attr.Value="my own attribute";
elem.UnhandledAttributes = new XmlAttribute[] {attr};
schema.Items.Add(elem);
schema.Write(Console.Out);

Produces:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element myns:blah="my own attribute" name="foo" type="xs:string"
xmlns:myns="http://myns.com" />
</xs:schema>
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4

P: n/a
On Sun, 21 Sep 2003 11:28:46 +0200, Oleg Tkachenko
<oleg@NO_SPAM_PLEASEtkachenko.com> wrote:
Eric Farr wrote:
Yes, I mean non-schema attributes. UnhandledAttributes is an array of
XmlAttribute objects. This looks like it is meant to be used when
reading a schema file. How would I use it in building the schema file?


Hmm, really. I've got no better idea than using dummy XmlDocument:
XmlSchema schema = new XmlSchema();
XmlSchemaElement elem = new XmlSchemaElement();
elem.Name = "foo";
elem.SchemaTypeName = new XmlQualifiedName("string",
"http://www.w3.org/2001/XMLSchema");
XmlDocument dummyDoc = new XmlDocument();
XmlAttribute attr = dummyDoc.CreateAttribute("myns:blah",
"http://myns.com");
attr.Value="my own attribute";
elem.UnhandledAttributes = new XmlAttribute[] {attr};
schema.Items.Add(elem);
schema.Write(Console.Out);

Produces:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element myns:blah="my own attribute" name="foo" type="xs:string"
xmlns:myns="http://myns.com" />
</xs:schema>


That gives me exactly what I was looking for. Thanks! It would have
been nice if .NET classes made this a little more straightforward, but
it least it works.
Nov 11 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.