5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
using System.Collections;
34
public static class Util
36
public static string Infoset (XmlNode nod)
38
StringBuilder sb = new StringBuilder ();
40
return sb.ToString ();
43
static void GetInfoset (XmlNode nod, StringBuilder sb)
45
switch (nod.NodeType) {
46
case XmlNodeType.Document:
47
GetInfoset (((XmlDocument)nod).DocumentElement, sb);
49
case XmlNodeType.Attribute:
50
if (nod.LocalName == "xmlns" && nod.NamespaceURI == "http://www.w3.org/2000/xmlns/") return;
51
sb.Append (" " + nod.NamespaceURI + ":" + nod.LocalName + "='" + nod.Value + "'");
54
case XmlNodeType.Element:
55
XmlElement elem = (XmlElement) nod;
56
sb.Append ("<" + elem.NamespaceURI + ":" + elem.LocalName);
58
ArrayList ats = new ArrayList ();
59
foreach (XmlAttribute at in elem.Attributes)
60
ats.Add (at.LocalName + " " + at.NamespaceURI);
64
foreach (string name in ats) {
65
string[] nn = name.Split (' ');
66
GetInfoset (elem.Attributes[nn[0], nn[1]], sb);
70
foreach (XmlNode cn in elem.ChildNodes)
76
sb.Append (nod.OuterXml);