Validating C # string as a valid anyURI XML Schema

Is there a better way to verify that a C # string is a valid xs: anyURI than the following?

public bool VerifyAnyURI(string anyUriValue)
{ 
    bool result = false;
    try
    {
        SoapAnyUri anyUri = new SoapAnyUri(anyUriValue);
        result = true;
    }
    catch (Exception)
    {
    }
    return result;
}

This constructor does not seem to throw any exceptions. Is any valid string technically valid anyURI?

+3
source share
1 answer

Looking at the constructor SoapAnyUriwith Reflector, it does not perform any validation at all.

The data type is defined as follows : anyURI

[:] anyURI (URI). anyURI (.. URI). , URI, [RFC 2396], [RFC 2732].

, Uri.TryCreate UriKind.RelativeOrAbsolute, , :

Uri uri;
bool valid = Uri.TryCreate(anyUriValue, UriKind.RelativeOrAbsolute, out uri);
+7

Source: https://habr.com/ru/post/1717847/


All Articles