Skip to content

Commit a8a8006

Browse files
committed
Support wildcards in the path search.
Allow multiple lines in the part search.
1 parent 0e4b771 commit a8a8006

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

StructuredXmlEditor/Data/DataTransformer.cs

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace StructuredXmlEditor.Data
1111
public class DataTransformer
1212
{
1313
//-----------------------------------------------------------------------
14-
public string ElementPath { get; set; }
14+
public List<string> ElementPaths { get; set; }
1515
public string OutputTemplate { get; set; }
1616

1717
//-----------------------------------------------------------------------
@@ -45,29 +45,61 @@ public bool TransformDocument(string path)
4545
//-----------------------------------------------------------------------
4646
public bool TransformDocument(XElement root)
4747
{
48-
var resourceType = ElementPath.Split('.')[0];
49-
if (root.Name != resourceType)
48+
var processed = false;
49+
foreach (var ElementPath in ElementPaths)
5050
{
51-
return false;
52-
}
51+
var pathParts = ElementPath.Split('.');
52+
var resourceType = pathParts[0];
53+
if (resourceType == "*")
54+
{
55+
var firstNode = pathParts[1];
5356

54-
var elementPath = ElementPath.Replace(resourceType + ".", "");
57+
var potentialStarts = root.Descendants(firstNode);
5558

56-
var matchingEls = GetElements(root, elementPath);
57-
if (matchingEls.Count > 0)
58-
{
59-
foreach (var el in matchingEls)
60-
{
61-
var parent = el.Parent;
62-
var transformed = TransformElement(root, el);
59+
var elementPath = ElementPath.Replace(resourceType + "." + firstNode + ".", "");
60+
foreach (var potentialRoot in potentialStarts)
61+
{
62+
var matchingEls = GetElements(potentialRoot, elementPath);
63+
if (matchingEls.Count > 0)
64+
{
65+
foreach (var el in matchingEls)
66+
{
67+
var parent = el.Parent;
68+
var transformed = TransformElement(root, el);
6369

64-
el.ReplaceWith(transformed);
70+
el.ReplaceWith(transformed);
71+
}
72+
73+
processed = true;
74+
}
75+
}
6576
}
77+
else
78+
{
79+
if (root.Name != resourceType || resourceType == "*")
80+
{
81+
continue;
82+
}
6683

67-
return true;
84+
var elementPath = ElementPath.Replace(resourceType + ".", "");
85+
86+
var matchingEls = GetElements(root, elementPath);
87+
if (matchingEls.Count > 0)
88+
{
89+
foreach (var el in matchingEls)
90+
{
91+
var parent = el.Parent;
92+
var transformed = TransformElement(root, el);
93+
94+
el.ReplaceWith(transformed);
95+
}
96+
97+
processed = true;
98+
}
99+
}
68100
}
69101

70-
return false;
102+
return processed;
71103
}
72104

73105
//-----------------------------------------------------------------------

StructuredXmlEditor/Tools/DataTransformerTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public DataTransformerTool(Workspace workspace) : base(workspace, "Data Transfor
8989
//-----------------------------------------------------------------------
9090
public void UpdatePreview()
9191
{
92-
DataTransformer.ElementPath = ElementPath;
92+
DataTransformer.ElementPaths = ElementPath.Split('\n').Select(e => e.Trim()).ToList();
9393
DataTransformer.OutputTemplate = OutputTemplate;
9494

9595
TransformError = null;

StructuredXmlEditor/View/CustomControls/DataTransformerToolView.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777

7878
<TextBox
7979
Margin="5"
80+
AcceptsReturn="True"
8081
Text="{Binding ElementPath, UpdateSourceTrigger=PropertyChanged, Delay=200}" />
8182
<TextBox
8283
Grid.Row="1"

0 commit comments

Comments
 (0)