How to install XmlAttribute as IsRequired?

Can we have the required XmlAttribute that does not allow null? I want to have something like IsRequired = true in XmlAttribute. It can be done? I know that there is "use =" required for XmlAttribute, but we cannot set its value, right? Is there a trick for this purpose?

+4
source share
1 answer

I'm still a bit confused about what you are trying to do, so I assume that you want to check your XML file before using it in your web service. In your case, your XML must have a specific attribute.

To do something like this, I usually create an XSD against XML that needs to be retrieved, and use it to validate it against XML. The XSD will contain information that XML must contain a specific node / attribute. You can use visual studio XSD editor to customize these elements.

This section should help you with the verification code after creating the XSD:

XML validation against XSD with reference to C #

+1
source

All Articles