Changeset 424


Ignore:
Timestamp:
Feb 25, 2008, 11:03:28 PM (16 years ago)
Author:
dai
Message:

System.Xml関連のクラスを仮実装してみた(まだ満足な機能レベルではない…)。

Location:
trunk
Files:
7 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/Classes/System/Xml/XmlDocument.ab

    r402 r424  
    77Class XmlDocument
    88    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
    918Public
    1019
     
    1322    */
    1423    Sub XmlDocument()
     24        XmlNode( "", "#document", "", Nothing )
    1525    End Sub
    1626
     
    2737    'End Sub
    2838
    29     Function AppendChild( newChild As XmlNode ) As XmlNode
    30         ' TODO: 実装
     39    /*!
     40    @brief  指定した値を使用して、XmlDeclaration ノードを作成します。
     41    */
     42    Function CreateXmlDeclaration( version As String, encoding As String, standalone As String ) As XmlDeclaration
     43        Return New XmlDeclaration( version ,encoding, standalone, This )
    3144    End Function
    3245
    33     Function CloneNode( deep As Boolean ) As XmlNode
    34         ' TODO: 実装
     46    /*!
     47    @brief  指定した名前を使用して要素を作成します。
     48    */
     49    Function CreateElement( name As String ) As XmlElement
     50        VerifyLocalName( name )
     51
     52        Return New XmlElement( "", name, "", This )
     53    End Function
     54
     55    /*!
     56    @brief  このノードとそのすべての子ノードを表すマークアップを取得します。
     57    @return このノードとそのすべての子ノードを格納しているマークアップ。
     58    */
     59    Override Function OuterXml() As String
     60        Return This.InnerXml
    3561    End Function
    3662
  • trunk/Include/Classes/System/Xml/XmlNode.ab

    r402 r424  
    66*/
    77Class XmlNode
     8
     9    'attributes As XmlAttributeCollection
     10    childNodes As XmlNodeList
     11    prefix As String
     12    localName As String
     13    namespaceURI As String
     14    ownerDocument As XmlDocument
     15    value As String
     16
     17    Function InnerXmlSupportedIndent( isIndent = False As Boolean, indent = 0 As Long ) As String
     18        Dim result = ""
     19        If Not ActiveBasic.IsNothing( childNodes ) Then
     20            ' 子ノード
     21            Foreach childNode In childNodes
     22                result += childNode.OwnerXmlSupportedIndent( isIndent, indent )
     23            Next
     24        End If
     25        Return result
     26    End Function
     27
     28    Function OwnerXmlSupportedIndent( isIndent = False As Boolean, indent = 0 As Long ) As String
     29        Dim indentStr = ""
     30        Dim crlfStr = ""
     31        If isIndent Then
     32            ' インデントをサポートする場合
     33            Dim i As Long
     34            For i=0 To ELM(indent)
     35                indentStr += Ex"\t"
     36            Next
     37
     38            crlfStr = Ex"\r\n"
     39        End If
     40
     41        If childNodes.Count = 0 Then
     42            Return indentStr + "<" + localName + " />" + crlfStr
     43        End If
     44
     45        Dim result = ""
     46
     47        ' 開始タグ
     48        result += indentStr + "<" + localName + ">" + crlfStr
     49
     50        ' 子ノードリスト
     51        result += InnerXmlSupportedIndent( isIndent, indent + 1 )
     52
     53        ' 終了タグ
     54        result += indentStr + "</" + localName + ">" + crlfStr
     55
     56        Return result
     57    End Function
     58
    859Public
    960
    10     attributes As XmlAttributeCollection
    11     childNodes As XmlNodeList
     61    /*!
     62    @brief  コンストラクタ
     63    */
     64    Sub XmlNode( prefix As String, localName As String, namespaceURI As String, doc As XmlDocument )
     65        This.prefix = prefix
     66        This.localName = localName
     67        This.namespaceURI = namespaceURI
     68        This.ownerDocument = doc
     69        This.value = Nothing
     70
     71        childNodes = New XmlNodeList()
     72    End Sub
     73
     74    /*!
     75    @brief  コンストラクタ
     76    */
     77    Sub XmlNode( data As String, doc As XmlDocument )
     78        This.prefix = Nothing
     79        This.localName = Nothing
     80        This.namespaceURI = Nothing
     81        This.ownerDocument = doc
     82        This.value = data
     83
     84        childNodes = Nothing
     85    End Sub
     86
     87
     88    '----------------------------------------------------------------
     89    ' パブリック プロパティ
     90    '----------------------------------------------------------------
    1291
    1392    /*!
    1493    @brief  名前またはインデックスによってアクセスできる属性のコレクションを表します。
    1594    */
    16     Function Attributes() As XmlAttributeCollection
    17         Return attributes
    18     End Function
     95    'Virtual Function Attributes() As XmlAttributeCollection
     96    '   Return attributes
     97    'End Function
    1998
    2099    /*!
    21100    @brief  子ノードリストを返します。
    22101    */
    23     Function ChildNodes() As XmlNodeList
     102    Virtual Function ChildNodes() As XmlNodeList
    24103        Return childNodes
    25104    End Function
     
    28107    @brief  ノードの最初の子を取得します。
    29108    */
    30     Function FirstChild() As XmlNode
     109    Virtual Function FirstChild() As XmlNode
    31110        If childNodes.Count = 0 Then
    32111            ' 子ノードが1つもないときはNothingを返す
     
    39118    @brief  子ノードが1つ以上あるかどうかを取得します。
    40119    */
    41     Function HasChildNodes() As Boolean
     120    Virtual Function HasChildNodes() As Boolean
    42121        Return Not ( childNodes.Count = 0 )
    43122    End Function
    44123
    45124    /*!
     125    @brief  このノードの子ノードだけを表すマークアップを取得または設定します。
     126    */
     127    Virtual Function InnerXml() As String
     128        Return InnerXmlSupportedIndent()
     129    End Function
     130
     131    /*!
     132    @brief  ノードのローカル名を取得します。
     133    @return ノードのローカル名。
     134    */
     135    Virtual Function LocalName() As String
     136        return localName
     137    End Function
     138
     139    /*!
     140    @brief  このノードの名前空間 URI を取得します。
     141    @return このノードの名前空間 URI。
     142    */
     143    Virtual Function NamespaceURI() As String
     144        return NamespaceURI
     145    End Function
     146
     147    /*!
     148    @brief  このノードとそのすべての子ノードを表すマークアップを取得します。
     149    @return このノードとそのすべての子ノードを格納しているマークアップ。
     150    */
     151    Virtual Function OuterXml() As String
     152        Return OwnerXmlSupportedIndent()
     153    End Function
     154
     155    /*!
     156    @brief  このノードが属する XmlDocument を取得します。
     157    @return このノードが属する XmlDocument。
     158    */
     159    Virtual Function OwnerDocument() As XmlDocument
     160        Return ownerDocument
     161    End Function
     162
     163    /*!
     164    @brief  このノードの名前空間プリフィックスを取得または設定します。
     165    @return このノードの名前空間プリフィックス。たとえば、プリフィックスは要素 <bk:book> の bk です。プリフィックスがない場合、このプロパティは String.Empty を返します。
     166    */
     167    Virtual Function Prefix() As String
     168        return prefix
     169    End Function
     170
     171   
     172
     173
     174    '----------------------------------------------------------------
     175    ' パブリック メソッド
     176    '----------------------------------------------------------------
     177
     178    /*!
    46179    @brief  このノードの子ノードリストの末尾に指定したノードを追加する。
    47180    */
    48     Function AppendChild( newChild As XmlNode ) As XmlNode
    49         ' TODO: 実装
     181    Virtual Function AppendChild( newChild As XmlNode ) As XmlNode
     182        childNodes.Add( newChild )
     183        Return newChild
    50184    End Function
    51185
     
    53187    @brief  ノードを複製する。
    54188    */
    55     Function Clone() As XmlNode
     189    Virtual Function Clone() As XmlNode
    56190        ' TODO: 実装
    57191    End Function
     
    60194    @brief  派生クラスでオーバーライドされた場合は、ノードの複製を作成する。
    61195    */
    62     Function CloneNode( deep As Boolean ) As XmlNode
     196    Virtual Function CloneNode( deep As Boolean ) As XmlNode
    63197        ' TODO: 実装
    64198    End Function
     
    67201    @brief  XmlNode のノードに対する Foreachスタイルの反復をサポートします。
    68202    */
    69     Function GetEnumerator() As IEnumerator
     203    Virtual Function GetEnumerator() As IEnumerator
    70204        ' TODO: 実装
    71205    End Function
     
    77211    @return 挿入されるノード。
    78212    */
    79     Function InsertAfter( newChild As XmlNode, refChild As XmlNode ) As XmlNode
     213    Virtual Function InsertAfter( newChild As XmlNode, refChild As XmlNode ) As XmlNode
    80214        ' TODO: 実装
    81215    End Function
     
    87221    @return 挿入されるノード。
    88222    */
    89     Function InsertBefore( newChild As XmlNode, refChild As XmlNode ) As XmlNode
     223    Virtual Function InsertBefore( newChild As XmlNode, refChild As XmlNode ) As XmlNode
    90224        ' TODO: 実装
    91225    End Function
     
    96230    @return 挿入されるノード。
    97231    */
    98     Function PrependChild( newChild As XmlNode ) As XmlNode
     232    Virtual Function PrependChild( newChild As XmlNode ) As XmlNode
    99233        ' TODO: 実装
    100234    End Function
     
    103237    @brief  現在のノードのすべての子ノードと属性の両方、またはそのいずれかを削除します。
    104238    */
    105     Sub RemoveAll()
     239    Virtual Sub RemoveAll()
    106240        ' TODO: 実装
    107241    End Sub
     
    112246    @return 削除されたノード。
    113247    */
    114     Function RemoveChild( oldChild As XmlNode ) As XmlNode
     248    Virtual Function RemoveChild( oldChild As XmlNode ) As XmlNode
    115249        ' TODO: 実装
    116250    End Function
     
    122256    @return 置き換えられたノード。
    123257    */
    124     Function ReplaceChild( newChild As XmlNode, oldChild As XmlNode ) As XmlNode
     258    Virtual Function ReplaceChild( newChild As XmlNode, oldChild As XmlNode ) As XmlNode
    125259        ' TODO: 実装
    126260    End Function
    127261
    128262End Class
     263
     264TypeDef XmlNodeList = System.Collections.Generic.List<XmlNode>
    129265
    130266
  • trunk/Include/Classes/index.ab

    r420 r424  
    9494#require "./System/Windows/Forms/misc.ab"
    9595#require "./System/Windows/Forms/PaintEventArgs.ab"
     96#require "./System/Xml/XmlAttribute.ab"
     97#require "./System/Xml/XmlCharacterData.ab"
     98#require "./System/Xml/XmlDeclaration.ab"
     99#require "./System/Xml/XmlDocument.ab"
     100#require "./System/Xml/XmlElement.ab"
     101#require "./System/Xml/XmlLinkedNode.ab"
     102#require "./System/Xml/XmlNode.ab"
     103#require "./System/Xml/XmlText.ab"
  • trunk/TestCase/SimpleTestCase/SimpleTestCase.idx

    r411 r424  
    3434#include "EncodingTest.ab"
    3535_ClearNamespaceImported
     36#include "XmlTest.ab"
     37_ClearNamespaceImported
     38
     39'リソースファイル
     40#include "resource.ab"
     41#resource "SimpleTestCase.rc"
  • trunk/TestCase/SimpleTestCase/SimpleTestCase.pj

    r411 r424  
    4242TypeInfoTest.ab
    4343EncodingTest.ab
     44XmlTest.ab
Note: See TracChangeset for help on using the changeset viewer.