Skip to content

Commit 1688cdf

Browse files
committed
#2138 fix isse with default object and simple elements in complex elements
1 parent 3653c39 commit 1688cdf

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Modules/DIM/BExIS.Dim.Helper/Mappings/MappingUtils.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,8 +1493,7 @@ public static XmlDocument GetConceptOutput(long metadataStructureId, long concep
14931493
//var simpleElements = metadata.SelectNodes(t);
14941494
if ((simpleElements == null || simpleElements.Count() == 0) && string.IsNullOrEmpty(complexMapping.Source.XPath) && complexMapping.Source.Name.ToLower().Equals("default")) // DEFAULT
14951495
{
1496-
1497-
string simpleTargetPath = complexTargetPath + "/"+ sTargetLinkElement.XPath + "[" + index + "]";
1496+
string simpleTargetPath = mergeXPaths(complexTargetPath, cTargetLinkElement.XPath, sTargetLinkElement.XPath + "[" + index + "]");
14981497

14991498
if (xTarget == null)
15001499
xTarget = XmlUtility.GenerateNodeFromXPath(concept, concept.DocumentElement, complexTargetPath); // generate target
@@ -1593,6 +1592,23 @@ private static string mergeXPaths(string directParent,string defaultParentPath,
15931592
return directParent + "/" + child.Replace(defaultParentPath, "").TrimStart('/');
15941593

15951594
}
1595+
// check if two xpath start with the same path
1596+
private static bool startWithSameXPath(string path1, string path2)
1597+
{
1598+
if (string.IsNullOrEmpty(path1) || string.IsNullOrEmpty(path2)) return false;
1599+
1600+
List<string> levelOfPath1 = path1.Split('/').ToList();
1601+
List<string> levelOfPath2 = path2.Split('/').ToList();
1602+
1603+
int minLevel = Math.Min(levelOfPath1.Count(), levelOfPath2.Count());
1604+
1605+
for (int i = 0; i < minLevel; i++)
1606+
{
1607+
if (!levelOfPath1[i].Equals(levelOfPath2[i])) return false;
1608+
}
1609+
1610+
return true;
1611+
}
15961612

15971613
private static string mergeXPaths(string directComplexSourceParent, string directSimpleSourcePath, string directTargetPath,string defaultTargetPath, string child, XmlDocument metadata)
15981614
{

0 commit comments

Comments
 (0)