Can we have a required XmlAttribute that does not allow null value? I want to have something like IsRequired = true in XmlAttribute. Can it be done? I know that there is a 'use="required"' for XmlAttribute, but we can't set its value, can we? Is there any trick to serve this purpose?
Asked
Active
Viewed 1,968 times
4
-
1I'm not entirely clear on what you want to happen if the attribute is null. If you just want it to get some default value, you can use `[System.ComponentModel.DefaultValue()]` – Martin Brenden Jul 12 '11 at 06:29
-
What are you trying to do? If you need attribute to have value simply fill it. – Ladislav Mrnka Jul 12 '11 at 08:57
-
I'm sorry to confuse you guys. What I'm trying to do is to have an attribute that force user to pass the value to it. Just like [DataMember(IsRequired = true)] in wcf. So, if the attribute is null, it will deny the request. – lhardj Jul 13 '11 at 06:25
1 Answers
1
I'm still a little confused by what you're trying to do, so i'm assuming that you wish to validate your input xml before attempting to use it in your webservice. In your case your XML needs to have a specific attribute.
To do something like that I typically create an XSD against the XML that should be received and use that to validate it against the XML. The XSD will contain the details that the XML must contain a certain node / attribute. You can use visual studio XSD editor to configure these items.
This topic should help you with the validation code once you're XSD is created:

Community
- 1
- 1

johnwinter
- 3,624
- 15
- 24