/// <summary> /// Parses the URL string to new instance of UrlAddress class /// </summary> /// <param name="url">The URL string</param> /// <returns>The instance of URLAddress class</returns> public static UrlAddress ParseUrlAddress(string url) { string urlString = url.Trim(); var regex = new Regex(@"^(?<scheme>\S+)://(?<host>\S+?)/((?<URLpath>\S+?)([?](?<parameters>\S+))?)?$"); Match match = regex.Match(urlString); if (match.Success) { var urlAddress = new UrlAddress(); urlAddress.Add(new Scheme(match.Groups["scheme"].Value)); urlAddress.Add(new Host(match.Groups["host"].Value)); if (match.Groups["URLpath"].Success) { urlAddress.Add(ParseUrlPath(match.Groups["URLpath"].Value)); if (match.Groups["parameters"].Success) { urlAddress.Add(ParseParameters(match.Groups["parameters"].Value)); } } return(urlAddress); } else { throw new ArgumentException("URL doesn't match to pattern"); } }
/// <summary> /// Converts the URL address to XML element /// </summary> /// <param name="urlAddress">The Url address</param> /// <returns>The XML element, that represents given UML address</returns> public XElement Convert(UrlAddress urlAddress) { var element = new XElement("urlAddress"); foreach (dynamic urlPart in urlAddress.Parts) { element.Add(PartToElement(urlPart)); } return(element); }