Namespace System Namespace Xml /*! @brief XMLドキュメントを表す */ Class XmlDocument Inherits XmlNode Sub VerifyLocalName( name As String ) If Object.ReferenceEquals( name, Nothing ) Then ' Throw System.ArgumentException() ElseIf name.Length = 0 Then ' Throw System.ArgumentException() End If End Sub Public /*! @brief コンストラクタ */ Sub XmlDocument() XmlNode( XmlNodeType.Document, "", "#document", "", Nothing ) End Sub /*! @brief コンストラクタ */ 'Sub XmlDocument( xmlImplementation As XmlImplementation ) 'End Sub /*! @brief コンストラクタ */ 'Sub XmlDocument( xmlNameTable As XmlNameTable ) 'End Sub '---------------------------------------------------------------- ' パブリック プロパティ '---------------------------------------------------------------- /*! @brief このノードとそのすべての子ノードを表すマークアップを取得します。 @return このノードとそのすべての子ノードを格納しているマークアップ。 */ Override Function OuterXml() As String Return This.InnerXml End Function '---------------------------------------------------------------- ' パブリック メソッド '---------------------------------------------------------------- /*! @brief 指定した値を使用して、XmlDeclaration ノードを作成します。 @param version XMLのバージョン番号。 encoding 文字コード。(例:"shift-jis", "UTF-8", "EUC-JP") standalone 外部DTDの参照が必要かどうか。"yes" or "no" */ Function CreateXmlDeclaration( version As String, encoding As String, standalone As String ) As XmlDeclaration Return New XmlDeclaration( version ,encoding, standalone, This ) End Function /*! @brief 指定した名前を使用して属性を作成します。 @param name 属性名 */ Function CreateAttribute( name As String) As XmlAttribute VerifyLocalName( name ) Return New XmlAttribute( "", name, "", This ) End Function /*! @brief 指定した名前を使用して要素を作成します。 @param name 要素名。 */ Function CreateElement( name As String ) As XmlElement VerifyLocalName( name ) Return New XmlElement( "", name, "", This ) End Function /*! @brief 指定した文字列を使用してテキストノードを作成します。 @param text 文字列。 */ Function CreateTextNode( text As String ) As XmlText Return New XmlText( text, This ) End Function /*! @brief 指定したストリームからXML文書を読み込む。 @param stream 読み込み先のストリーム。 */ Virtual Sub Load( inStream As System.IO.Stream ) Dim length = inStream.Length As DWord Dim xmlBuffer = calloc( length + 1 ) As *StrChar inStream.Read( xmlBuffer As *Byte, 0, length ) inStream.Close() Dim xmlString = New String( xmlBuffer ) free( xmlBuffer ) This.RemoveAll() ActiveBasic.Xml.Parser.Parse( xmlString, This ) End Sub /*! @brief 指定したファイルからXML文書を読み込む。 @param ファイルパス。 */ Virtual Sub Load( filename As String ) Dim fileStream As System.IO.FileStream( filename, System.IO.FileMode.Open, System.IO.FileAccess.Read ) Load( fileStream ) End Sub /*! @brief 指定したストリームにXML文書を保存する。 @param stream 保存先のストリーム。 */ Virtual Sub Save( outStream As System.IO.Stream ) Dim xmlStr = InnerXmlSupportedIndent( True ) outStream.Write( xmlStr.StrPtr As *Byte, 0, xmlStr.Length * SizeOf( StrChar ) ) outStream.Close() End Sub /*! @brief 指定したファイルにXML文書を保存する。 @param ファイルパス。 */ Virtual Sub Save( filename As String ) Dim fileStream As System.IO.FileStream( filename, System.IO.FileMode.Create, System.IO.FileAccess.Write ) Save( fileStream ) End Sub End Class End Namespace End Namespace