Skip to content

Commit 8a215dc

Browse files
committed
'Auto-commit changes made by Claude
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>'
1 parent 11a68ab commit 8a215dc

File tree

5 files changed

+163
-3
lines changed

5 files changed

+163
-3
lines changed

csharp/Platform.Data.Doublets.Xml.Exporter/Platform.Data.Doublets.Xml.Exporter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

csharp/Platform.Data.Doublets.Xml.Importer/Platform.Data.Doublets.Xml.Importer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

csharp/Platform.Data.Doublets.Xml/DefaultXmlStorage.cs

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)

csharp/Platform.Data.Doublets.Xml/XmlExporter.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ private void ExportNode(XmlWriter xmlWriter, TLinkAddress documentLinkAddress,TL
5050
{
5151
ExportElement(xmlWriter, documentLinkAddress, nodeLinkAddress, cancellationToken);
5252
}
53+
else if (_storage.IsComment(nodeLinkAddress))
54+
{
55+
ExportComment(xmlWriter, nodeLinkAddress);
56+
}
57+
else if (_storage.IsProcessingInstruction(nodeLinkAddress))
58+
{
59+
ExportProcessingInstruction(xmlWriter, nodeLinkAddress);
60+
}
61+
else if (_storage.IsCData(nodeLinkAddress))
62+
{
63+
ExportCData(xmlWriter, nodeLinkAddress);
64+
}
5365
else
5466
{
5567
throw new ArgumentException($"{nodeLinkAddress} is not a node link address.");
@@ -88,5 +100,23 @@ private void ExportTextNode(XmlWriter xmlWriter, TLinkAddress textNodeLinkAddres
88100
var text = _storage.GetTextNode(textNodeLinkAddress);
89101
xmlWriter.WriteString(text);
90102
}
103+
104+
private void ExportComment(XmlWriter xmlWriter, TLinkAddress commentLinkAddress)
105+
{
106+
var comment = _storage.GetComment(commentLinkAddress);
107+
xmlWriter.WriteComment(comment);
108+
}
109+
110+
private void ExportProcessingInstruction(XmlWriter xmlWriter, TLinkAddress processingInstructionLinkAddress)
111+
{
112+
var (target, data) = _storage.GetProcessingInstruction(processingInstructionLinkAddress);
113+
xmlWriter.WriteProcessingInstruction(target, data);
114+
}
115+
116+
private void ExportCData(XmlWriter xmlWriter, TLinkAddress cDataLinkAddress)
117+
{
118+
var cData = _storage.GetCData(cDataLinkAddress);
119+
xmlWriter.WriteCData(cData);
120+
}
91121
}
92122
}

csharp/Platform.Data.Doublets.Xml/XmlImporter.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ private TLinkAddress ImportNodes(XmlReader reader, CancellationToken cancellatio
106106
parent.Children.Add(textNodeAddress);
107107
break;
108108
}
109+
case XmlNodeType.Comment:
110+
{
111+
var commentNodeAddress = _storage.CreateComment(reader.Value);
112+
var parent = elements.Peek();
113+
parent.Children.Add(commentNodeAddress);
114+
break;
115+
}
116+
case XmlNodeType.ProcessingInstruction:
117+
{
118+
var processingInstructionNodeAddress = _storage.CreateProcessingInstruction(reader.Name, reader.Value);
119+
var parent = elements.Peek();
120+
parent.Children.Add(processingInstructionNodeAddress);
121+
break;
122+
}
123+
case XmlNodeType.CDATA:
124+
{
125+
var cDataNodeAddress = _storage.CreateCData(reader.Value);
126+
var parent = elements.Peek();
127+
parent.Children.Add(cDataNodeAddress);
128+
break;
129+
}
109130
case XmlNodeType.Attribute:
110131
{
111132

0 commit comments

Comments
 (0)