Line | |
---|
1 | using System.Xml;
|
---|
2 |
|
---|
3 | namespace SharpVectors.Xml
|
---|
4 | {
|
---|
5 | /// <summary>
|
---|
6 | /// XML namespace manager allowing to fire events when namespace is not found
|
---|
7 | /// </summary>
|
---|
8 | public sealed class DynamicXmlNamespaceManager : XmlNamespaceManager
|
---|
9 | {
|
---|
10 | /// <summary>
|
---|
11 | /// Event handler type
|
---|
12 | /// </summary>
|
---|
13 | public delegate string ResolveEventHandler(string prefix);
|
---|
14 |
|
---|
15 | /// <summary>
|
---|
16 | /// Occurs when trying to resolve an unknown namespace.
|
---|
17 | /// </summary>
|
---|
18 | public event ResolveEventHandler Resolve;
|
---|
19 |
|
---|
20 | /// <summary>
|
---|
21 | /// Initializes a new instance of the <see cref="DynamicXmlNamespaceManager"/> class.
|
---|
22 | /// </summary>
|
---|
23 | public DynamicXmlNamespaceManager()
|
---|
24 | : base(new NameTable())
|
---|
25 | {
|
---|
26 | }
|
---|
27 |
|
---|
28 | /// <summary>
|
---|
29 | /// Initializes a new instance of the <see cref="DynamicXmlNamespaceManager"/> class.
|
---|
30 | /// </summary>
|
---|
31 | /// <param name="xmlNameTable">The XML name table.</param>
|
---|
32 | public DynamicXmlNamespaceManager(XmlNameTable xmlNameTable)
|
---|
33 | : base(xmlNameTable)
|
---|
34 | {
|
---|
35 | }
|
---|
36 |
|
---|
37 | /// <summary>
|
---|
38 | /// Gets the namespace URI for the specified prefix.
|
---|
39 | /// </summary>
|
---|
40 | /// <param name="prefix">The prefix whose namespace URI you want to resolve. To match the default namespace, pass String.Empty.</param>
|
---|
41 | /// <returns>
|
---|
42 | /// Returns the namespace URI for <paramref name="prefix"/> or null if there is no mapped namespace. The returned string is atomized.
|
---|
43 | /// For more information on atomized strings, see <see cref="T:System.Xml.XmlNameTable"/>.
|
---|
44 | /// </returns>
|
---|
45 | public override string LookupNamespace(string prefix)
|
---|
46 | {
|
---|
47 | string uri = base.LookupNamespace(prefix);
|
---|
48 | if (uri == null)
|
---|
49 | uri = this.Resolve(prefix);
|
---|
50 |
|
---|
51 | return uri;
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.