Add cdata manipulators

Clanker: claude-sonnet_4.6
This commit is contained in:
Dominic Höglinger 2026-04-24 04:45:42 +02:00
parent 154647083c
commit c694fe8b17

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using Sprache; using Sprache;
using XNeedle.Parser; using XNeedle.Parser;
using XNeedle.Parser.Elements; using XNeedle.Parser.Elements;
@ -45,6 +46,28 @@ namespace XNeedle.Transformation
return txt; return txt;
} }
public static string cdata(Context ctx)
{
if (ctx.Node is null) return "";
var cdataNode = ctx.Node.Nodes().OfType<System.Xml.Linq.XCData>().FirstOrDefault();
return cdataNode?.Value ?? "";
}
public static string cdata(Context ctx, string txt)
{
if (ctx.Node is null) return "";
var cdataNode = ctx.Node.Nodes().OfType<System.Xml.Linq.XCData>().FirstOrDefault();
if (cdataNode != null)
{
cdataNode.Value = txt;
}
else
{
ctx.Node.Add(new System.Xml.Linq.XCData(txt));
}
return txt;
}
public static string attr(Context ctx, string name, string value) public static string attr(Context ctx, string name, string value)
{ {
if (ctx.Node is null) return ""; if (ctx.Node is null) return "";