Embedded XML Files

Topics: Developer Forum
Apr 13, 2007 at 12:53 PM
What's the logic behind this being embedded?

Also, is it possible to load individual XML files?

Thanks,

- Andrew
Coordinator
Apr 13, 2007 at 10:37 PM
The idea behind having an embedded xml file is that the assembly and the rules can be shipped as one assembly. So it is mostly to simplify deployment.

Yes you can add xml files individually. In fact ConfigurationService contains a number of methods for adding xml in different ways. I have listed them below. Or you could have a look at the chm (ConfigurationService is in the ValidationFramework.Configuration namespace).


/// <summary>
/// Add validation from a particular XML file.
/// </summary>
/// <param name="xmlFileInfo">The <see cref="FileInfo"/> to the XML data.</param>
/// <exception cref="ArgumentNullException"><paramref name="xmlFileInfo"/> is null.</exception>
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public static void AddXmlFile(FileInfo xmlFileInfo)
  
/// <summary>
/// Add validation from a particular XML file.
/// </summary>
/// <param name="xmlFileUrl">The URL for the file containing the XML data.</param>
/// <exception cref="ArgumentNullException"><paramref name="xmlFileUrl"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="xmlFileUrl"/> is a 
<see cref="string.Empty"/>.</exception>
public static void AddXmlFile(string xmlFileUrl)
 
/// <summary>
/// Add all validation definitions from a directory tree.
/// </summary>
/// <remarks>Assume that any file named <c>*.validation.xml</c> is a validation 
definition document.</remarks>
/// <param name="directoryInfo">a directory</param>
/// <exception cref="ArgumentNullException"><paramref name="directoryInfo"/> is null.</exception>
public static void AddDirectory(DirectoryInfo directoryInfo)
  
/// <summary>
/// Add validation definitions from a <c>string</c>
/// </summary>
/// <param name="xml">The <see cref="string"/> containing the XML data.</param>
/// <exception cref="ArgumentNullException"><paramref name="xml"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="xml"/> is a 
<see cref="string.Empty"/>.</exception>
public static void AddXmlString(string xml)
 
/// <summary>
/// Adds the validation in the <see cref="XmlTextReader"/> after validating it against the 
validationFramework-validationDefinition-1.5 schema.
/// </summary>
/// <param name="xmlTextReader">The XmlTextReader that contains the validation.</param>
/// <exception cref="ArgumentNullException"><paramref name="xmlTextReader"/> is null.</exception>
public static void AddXmlReader(XmlTextReader xmlTextReader)
 
/// <summary>
/// Read validation definitions from a URL.
/// </summary>
/// <param name="url">a URL</param>
/// <exception cref="ArgumentNullException"><paramref name="url"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="url"/> is a <see cref="string.Empty"/>.</exception>
public static void AddUrl(string url)
 
/// <summary>
/// Read validation definitions from a <see cref="Uri"/>.
/// </summary>
/// <param name="uri">a <see cref="Uri" /> to read the mappings from.</param>
/// <returns>This configuration object.</returns>
/// <exception cref="ArgumentNullException"><paramref name="uri"/> is null.</exception>
public static void AddUrl(Uri uri)
  
/// <summary>
/// Read validation definitions from an <see cref="XmlDocument"/>.
/// </summary>
/// <param name="xmlDocument">A loaded <see cref="XmlDocument"/> that contains the validation.</param>
/// <exception cref="ArgumentNullException"><paramref name="xmlDocument"/> is null.</exception>
public static void AddDocument(XmlDocument xmlDocument)
  
/// <summary>
/// Add validation definition from a <see cref="Stream"/>.
/// </summary>
/// <param name="xmlInputStream">The stream containing XML</param>
/// <remarks>
/// The <see cref="Stream"/> passed in through the parameter <c>xmlInputStream</c> is not 
<b>guaranteed</b> to be cleaned up by this method.  It is the callers responsibility to 
ensure that the <c>xmlInputStream</c> is properly handled when this method completes.
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="xmlInputStream"/> is null.</exception>
public static void AddInputStream(Stream xmlInputStream)
  
/// <summary>
/// Adds the validation definitions in the Resource of the <see cref="Assembly"/>.
/// </summary>
/// <param name="path">The path to the Resource file in the <see cref="Assembly"/></param>
/// <param name="assembly">The <see cref="Assembly"/> that contains the Resource file.</param>
/// <exception cref="ArgumentNullException"><paramref name="assembly"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="path"/> is a <see cref="string.Empty"/>.</exception>
public static void AddResource(string path, Assembly assembly)
  
/// <summary>
/// Add validation definitions from an application resource, using a convention. The 
class <c>Foo.Bar.Foo</c> is validation definitions by the resource named 
<c>Foo.Bar.Foo.validation.xml</c>, embedded in the class' assembly.
/// </summary>
/// <param name="persistentClass">The type to map.</param>
/// <returns>This configuration object.</returns>
/// <remarks>
/// If the mappings and classes are defined in different assemblies or don't follow 
the naming convention, then this method cannot be used.
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="persistentClass"/> is 
null.</exception>
public static void AddClass(Type persistentClass)
  
/// <summary>
/// Adds all of the Assembly's Resource files that end with "<c>.validation.xml</c>"
/// </summary>
/// <param name="assemblyName">The name of the <see cref="Assembly"/> to load.</param>
/// <remarks>
/// The <see cref="Assembly"/> must be in the local bin, probing path, or GAC so that 
the <see cref="Assembly"/> can be loaded by name.  If these conditions are not 
satisfied then your code should load the <see cref="Assembly"/> and call the override 
<see cref="AddAssembly(Assembly)"/> instead.
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="assemblyName"/> is 
null.</exception>
/// <exception cref="ArgumentException"><paramref name="assemblyName"/> is a 
<see cref="string.Empty"/>.</exception>
public static void AddAssembly(string assemblyName)
  
/// <summary>
/// Adds all of the Assembly's Resource files that end with "<c>.validation.xml</c>" 
/// </summary>
/// <param name="assembly">The <see cref="Assembly"/> to load.</param>
/// <exception cref="ArgumentNullException"><paramref name="assembly"/> is null.</exception>
public static void AddAssembly(Assembly assembly)
Apr 14, 2007 at 6:03 AM
Marvellous! Pretty comprehensive I see:)

Thanks,

- Andrew