source: trunk/Include/Classes/System/Xml/XmlDocument.ab@ 468

Last change on this file since 468 was 468, checked in by イグトランス (egtra), 16 years ago

TextWriter, StreamWriterの追加。
SPrintfの浮動小数点数変換で、NaN, Infiniteの出力に対応。
PathとDirectoryInfoのCreateDirectoryで、対象が既に存在するときには例外を投げないように修正。
SimpleTestCase内で使用する一時フォルダの場所にGetTempPathで取得する版を追加(コメントアウト)。

File size: 3.8 KB
Line 
1Namespace System
2Namespace Xml
3
4/*!
5@brief XMLドキュメントを表す
6*/
7Class XmlDocument
8 Inherits XmlNode
9
10 Sub VerifyLocalName( name As String )
11 If Object.ReferenceEquals( name, Nothing ) Then
12 ' Throw System.ArgumentException()
13 ElseIf name.Length = 0 Then
14 ' Throw System.ArgumentException()
15 End If
16 End Sub
17
18Public
19
20 /*!
21 @brief コンストラクタ
22 */
23 Sub XmlDocument()
24 XmlNode( XmlNodeType.Document, "", "#document", "", Nothing )
25 End Sub
26
27 /*!
28 @brief コンストラクタ
29 */
30 'Sub XmlDocument( xmlImplementation As XmlImplementation )
31 'End Sub
32
33 /*!
34 @brief コンストラクタ
35 */
36 'Sub XmlDocument( xmlNameTable As XmlNameTable )
37 'End Sub
38
39
40 '----------------------------------------------------------------
41 ' パブリック プロパティ
42 '----------------------------------------------------------------
43
44 /*!
45 @brief このノードとそのすべての子ノードを表すマークアップを取得します。
46 @return このノードとそのすべての子ノードを格納しているマークアップ。
47 */
48 Override Function OuterXml() As String
49 Return This.InnerXml
50 End Function
51
52
53 '----------------------------------------------------------------
54 ' パブリック メソッド
55 '----------------------------------------------------------------
56
57 /*!
58 @brief 指定した値を使用して、XmlDeclaration ノードを作成します。
59 @param version XMLのバージョン番号。
60 encoding 文字コード。(例:"shift-jis", "UTF-8", "EUC-JP")
61 standalone 外部DTDの参照が必要かどうか。"yes" or "no"
62 */
63 Function CreateXmlDeclaration( version As String, encoding As String, standalone As String ) As XmlDeclaration
64 Return New XmlDeclaration( version ,encoding, standalone, This )
65 End Function
66
67 /*!
68 @brief 指定した名前を使用して属性を作成します。
69 @param name 属性名
70 */
71 Function CreateAttribute( name As String) As XmlAttribute
72 VerifyLocalName( name )
73
74 Return New XmlAttribute( "", name, "", This )
75 End Function
76
77 /*!
78 @brief 指定した名前を使用して要素を作成します。
79 @param name 要素名。
80 */
81 Function CreateElement( name As String ) As XmlElement
82 VerifyLocalName( name )
83
84 Return New XmlElement( "", name, "", This )
85 End Function
86
87 /*!
88 @brief 指定した文字列を使用してテキストノードを作成します。
89 @param text 文字列。
90 */
91 Function CreateTextNode( text As String ) As XmlText
92 Return New XmlText( text, This )
93 End Function
94
95 /*!
96 @brief 指定したストリームからXML文書を読み込む。
97 @param stream 読み込み先のストリーム。
98 */
99 Virtual Sub Load( inStream As System.IO.Stream )
100 Dim length = inStream.Length As DWord
101 Dim xmlBuffer = calloc( length + 1 ) As *StrChar
102 inStream.Read( xmlBuffer As *Byte, 0, length )
103 inStream.Close()
104 Dim xmlString = New String( xmlBuffer )
105 free( xmlBuffer )
106
107 This.RemoveAll()
108 ActiveBasic.Xml.Parser.Parse( xmlString, This )
109 End Sub
110
111 /*!
112 @brief 指定したファイルからXML文書を読み込む。
113 @param ファイルパス。
114 */
115 Virtual Sub Load( filename As String )
116 Dim fileStream As System.IO.FileStream( filename, System.IO.FileMode.Open, System.IO.FileAccess.Read )
117 Load( fileStream )
118 End Sub
119
120 /*!
121 @brief 指定したストリームにXML文書を保存する。
122 @param stream 保存先のストリーム。
123 */
124 Virtual Sub Save( outStream As System.IO.Stream )
125 Dim xmlStr = InnerXmlSupportedIndent( True )
126 outStream.Write( xmlStr.StrPtr As *Byte, 0, xmlStr.Length * SizeOf( StrChar ) )
127 outStream.Close()
128 End Sub
129
130 /*!
131 @brief 指定したファイルにXML文書を保存する。
132 @param ファイルパス。
133 */
134 Virtual Sub Save( filename As String )
135 Dim fileStream As System.IO.FileStream( filename, System.IO.FileMode.Create, System.IO.FileAccess.Write )
136 Save( fileStream )
137 End Sub
138
139 /*!
140 @brief 指定したテキストライタにXML文書を保存する。
141 @param テキストライタ。
142 */
143 Virtual Sub Save( writer As System.IO.TextWriter )
144 writer.Write(InnerXmlSupportedIndent( True ))
145 End Sub
146End Class
147
148
149End Namespace
150End Namespace
Note: See TracBrowser for help on using the repository browser.