@@ -103,6 +103,12 @@ private class Unindex : ISequenceIndex<TLinkAddress>
103103
104104 public TLinkAddress TextNodeType { get ; }
105105
106+ public TLinkAddress CommentType { get ; }
107+
108+ public TLinkAddress ProcessingInstructionType { get ; }
109+
110+ public TLinkAddress CDataType { get ; }
111+
106112 public TLinkAddress AttributeType { get ; }
107113
108114 public TLinkAddress AttributePrefixType { get ; }
@@ -182,6 +188,9 @@ public DefaultXmlStorage(ILinks<TLinkAddress> links, IConverter<IList<TLinkAddre
182188 ElementChildrenNodesType = links . GetOrCreate ( Type , StringToUnicodeSequenceConverter . Convert ( nameof ( ElementChildrenNodesType ) ) ) ;
183189 EmptyElementChildrenNodesType = links . GetOrCreate ( Type , StringToUnicodeSequenceConverter . Convert ( nameof ( EmptyElementChildrenNodesType ) ) ) ;
184190 TextNodeType = links . GetOrCreate ( Type , StringToUnicodeSequenceConverter . Convert ( nameof ( TextNodeType ) ) ) ;
191+ CommentType = links . GetOrCreate ( Type , StringToUnicodeSequenceConverter . Convert ( nameof ( CommentType ) ) ) ;
192+ ProcessingInstructionType = links . GetOrCreate ( Type , StringToUnicodeSequenceConverter . Convert ( nameof ( ProcessingInstructionType ) ) ) ;
193+ CDataType = links . GetOrCreate ( Type , StringToUnicodeSequenceConverter . Convert ( nameof ( CDataType ) ) ) ;
185194
186195 // Attribute
187196 AttributeType = links . GetOrCreate ( Type , StringToUnicodeSequenceConverter . Convert ( nameof ( AttributeType ) ) ) ;
@@ -393,7 +402,10 @@ public bool IsNode(TLinkAddress possibleXmlNode)
393402 var isElement = IsElementNode ( possibleXmlNode ) ;
394403 var isTextNode = IsTextNode ( possibleXmlNode ) ;
395404 var isAttribute = IsAttribute ( possibleXmlNode ) ;
396- return isElement || isTextNode || isAttribute ;
405+ var isComment = IsComment ( possibleXmlNode ) ;
406+ var isProcessingInstruction = IsProcessingInstruction ( possibleXmlNode ) ;
407+ var isCData = IsCData ( possibleXmlNode ) ;
408+ return isElement || isTextNode || isAttribute || isComment || isProcessingInstruction || isCData ;
397409 }
398410
399411 #region Document
@@ -556,6 +568,103 @@ public string GetTextNode(TLinkAddress textNodeLinkAddress)
556568
557569 #endregion
558570
571+ #region Comment
572+
573+ public bool IsComment ( TLinkAddress commentLinkAddress )
574+ {
575+ var possibleCommentType = Links . GetSource ( commentLinkAddress ) ;
576+ return EqualityComparer . Equals ( possibleCommentType , CommentType ) ;
577+ }
578+
579+ public TLinkAddress CreateComment ( string text )
580+ {
581+ var contentLink = CreateString ( text ) ;
582+ return Links . GetOrCreate ( CommentType , contentLink ) ;
583+ }
584+
585+ public void EnsureIsComment ( TLinkAddress possibleCommentLinkAddress )
586+ {
587+ if ( ! IsComment ( possibleCommentLinkAddress ) )
588+ {
589+ throw new ArgumentException ( $ "{ possibleCommentLinkAddress } is not a comment node link address") ;
590+ }
591+ }
592+
593+ public string GetComment ( TLinkAddress commentLinkAddress )
594+ {
595+ EnsureIsComment ( commentLinkAddress ) ;
596+ var contentLink = Links . GetTarget ( commentLinkAddress ) ;
597+ return GetString ( contentLink ) ;
598+ }
599+
600+ #endregion
601+
602+ #region ProcessingInstruction
603+
604+ public bool IsProcessingInstruction ( TLinkAddress processingInstructionLinkAddress )
605+ {
606+ var possibleProcessingInstructionType = Links . GetSource ( processingInstructionLinkAddress ) ;
607+ return EqualityComparer . Equals ( possibleProcessingInstructionType , ProcessingInstructionType ) ;
608+ }
609+
610+ public TLinkAddress CreateProcessingInstruction ( string target , string data )
611+ {
612+ var targetLink = CreateString ( target ) ;
613+ var dataLink = CreateString ( data ) ;
614+ var contentLink = Links . GetOrCreate ( targetLink , dataLink ) ;
615+ return Links . GetOrCreate ( ProcessingInstructionType , contentLink ) ;
616+ }
617+
618+ public void EnsureIsProcessingInstruction ( TLinkAddress possibleProcessingInstructionLinkAddress )
619+ {
620+ if ( ! IsProcessingInstruction ( possibleProcessingInstructionLinkAddress ) )
621+ {
622+ throw new ArgumentException ( $ "{ possibleProcessingInstructionLinkAddress } is not a processing instruction node link address") ;
623+ }
624+ }
625+
626+ public ( string target , string data ) GetProcessingInstruction ( TLinkAddress processingInstructionLinkAddress )
627+ {
628+ EnsureIsProcessingInstruction ( processingInstructionLinkAddress ) ;
629+ var contentLink = Links . GetTarget ( processingInstructionLinkAddress ) ;
630+ var targetLink = Links . GetSource ( contentLink ) ;
631+ var dataLink = Links . GetTarget ( contentLink ) ;
632+ return ( GetString ( targetLink ) , GetString ( dataLink ) ) ;
633+ }
634+
635+ #endregion
636+
637+ #region CData
638+
639+ public bool IsCData ( TLinkAddress cDataLinkAddress )
640+ {
641+ var possibleCDataType = Links . GetSource ( cDataLinkAddress ) ;
642+ return EqualityComparer . Equals ( possibleCDataType , CDataType ) ;
643+ }
644+
645+ public TLinkAddress CreateCData ( string text )
646+ {
647+ var contentLink = CreateString ( text ) ;
648+ return Links . GetOrCreate ( CDataType , contentLink ) ;
649+ }
650+
651+ public void EnsureIsCData ( TLinkAddress possibleCDataLinkAddress )
652+ {
653+ if ( ! IsCData ( possibleCDataLinkAddress ) )
654+ {
655+ throw new ArgumentException ( $ "{ possibleCDataLinkAddress } is not a CDATA node link address") ;
656+ }
657+ }
658+
659+ public string GetCData ( TLinkAddress cDataLinkAddress )
660+ {
661+ EnsureIsCData ( cDataLinkAddress ) ;
662+ var contentLink = Links . GetTarget ( cDataLinkAddress ) ;
663+ return GetString ( contentLink ) ;
664+ }
665+
666+ #endregion
667+
559668 #region Attribute
560669
561670 public bool IsAttribute ( TLinkAddress attributeLinkAddress )
0 commit comments