-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKmlFile-Ignore-Namespaces.cs.patch
More file actions
113 lines (108 loc) · 3.82 KB
/
KmlFile-Ignore-Namespaces.cs.patch
File metadata and controls
113 lines (108 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Index: SharpKml/Engine/KmlFile.cs
===================================================================
--- SharpKml/Engine/KmlFile.cs (revision 44542)
+++ SharpKml/Engine/KmlFile.cs (working copy)
@@ -106,7 +106,7 @@
/// <exception cref="System.Xml.XmlException">
/// An error occurred while parsing the KML.
/// </exception>
- public static KmlFile Load(Stream input)
+ public static KmlFile Load(Stream input,bool namespaces = true)
{
if (input == null)
{
@@ -115,10 +115,12 @@
using (var reader = new StreamReader(input))
{
- return Load(reader);
+ return Load(reader,namespaces);
}
}
+
+
/// <summary>
/// Loads a KmlFile using the specified KML data.
/// </summary>
@@ -137,7 +139,7 @@
/// <exception cref="System.Xml.XmlException">
/// An error occurred while parsing the KML.
/// </exception>
- public static KmlFile Load(TextReader reader)
+ public static KmlFile Load(TextReader reader, bool namespaces = true)
{
if (reader == null)
{
@@ -145,11 +147,53 @@
}
KmlFile file = new KmlFile();
- file.Parse(reader);
+ file.Parse(reader,namespaces);
return file;
}
/// <summary>
+ /// Loads a KmlFile using the specified KMZ data.
+ /// </summary>
+ /// <param name="kmz">The KmzFile containing the KML data.</param>
+ /// <param name="namespaces">true to allow namespace support; false to ignore namespaces.</param>
+ /// <returns>
+ /// A KmlFile representing the default KML file in the specified KMZ archive
+ /// or null if no KML data was found.
+ /// </returns>
+ /// <remarks>
+ /// This method checks for duplicate Id's in the file and throws an
+ /// exception if duplicate Id's are found. To enable duplicate Id's
+ /// use the <see cref="Parser"/> class and pass the root element
+ /// to <see cref="Create"/>.
+ /// </remarks>
+ /// <exception cref="ArgumentNullException">kmz is null.</exception>
+ /// <exception cref="ObjectDisposedException">
+ /// <see cref="KmzFile.Dispose"/> has been called on kmz.
+ /// </exception>
+ /// <exception cref="System.Xml.XmlException">
+ /// An error occurred while parsing the KML.
+ /// </exception>
+ public static KmlFile LoadFromKmz(IKmzReader kmz, bool namespaces = true)
+ {
+ if (kmz == null)
+ {
+ throw new ArgumentNullException("kmz");
+ }
+
+ string kml = kmz.ReadKml();
+ if (kml != null)
+ {
+ KmlFile instance = new KmlFile();
+ using (var stream = new StringReader(kml))
+ {
+ instance.Parse(stream,namespaces);
+ }
+ return instance;
+ }
+ return null;
+ }
+
+ /// <summary>
/// Searches for a <see cref="KmlObject"/> with the specified
/// <see cref="KmlObject.Id"/>.
/// </summary>
@@ -281,11 +325,19 @@
}
}
- private void Parse(TextReader input)
+ private void Parse(TextReader input, bool namespaces)
{
Parser parser = new Parser();
parser.ElementAdded += (s, e) => this.OnElementAdded(e.Element);
- parser.Parse(input);
+ if (namespaces)
+ {
+ parser.Parse(input);
+ }
+ else
+ {
+ parser.ParseString(input.ReadToEnd(),false);
+ }
+
this.Root = parser.Root;
}
}