From: <bo...@us...> - 2013-04-14 18:52:22
|
Revision: 530 http://sourceforge.net/p/xmlunit/code/530 Author: bodewig Date: 2013-04-14 18:52:18 +0000 (Sun, 14 Apr 2013) Log Message: ----------- replace in XPath was only needed because the very first level has a path of / - avoid it Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java trunk/xmlunit/src/main/net-core/diff/XPathContext.cs Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java 2013-04-14 18:30:29 UTC (rev 529) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java 2013-04-14 18:52:18 UTC (rev 530) @@ -135,17 +135,20 @@ } public String getXPath() { - String xpath = getXPath(path.descendingIterator()); - return xpath.replace(SEP + SEP, SEP); + return getXPath(path.descendingIterator()); } private String getXPath(Iterator<Level> dIterator) { if (!dIterator.hasNext()) { - return ""; + return EMPTY; } Level l = dIterator.next(); if (null == l.xpath) { - l.xpath = getXPath(dIterator) + SEP + l.expression; + String previous = getXPath(dIterator); + if (!SEP.equals(previous)) { + previous += SEP; + } + l.xpath = previous + l.expression; } return l.xpath; } Modified: trunk/xmlunit/src/main/net-core/diff/XPathContext.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/XPathContext.cs 2013-04-14 18:30:29 UTC (rev 529) +++ trunk/xmlunit/src/main/net-core/diff/XPathContext.cs 2013-04-14 18:52:18 UTC (rev 530) @@ -40,7 +40,7 @@ } else { this.uri2Prefix = new Dictionary<string, string>(uri2Prefix); } - path.AddLast(new Level("")); + path.AddLast(new Level(string.Empty)); } public void NavigateToChild(int index) { @@ -128,8 +128,7 @@ public string XPath { get { - String xpath = GetXPath(path.Last); - return xpath.Replace(SEP + SEP, SEP); + return GetXPath(path.Last); } } @@ -139,8 +138,11 @@ } Level level = l.Value; if (null == level.XPath) { - level.XPath = GetXPath(l.Previous) - + SEP + level.Expression; + string previous = GetXPath(l.Previous); + if (previous != SEP) { + previous += SEP; + } + level.XPath = previous + level.Expression; } return level.XPath; } @@ -151,7 +153,7 @@ if (ns != null) { uri2Prefix.TryGetValue(ns, out p); } - return (p == null ? "" : p + ":") + name.Name; + return (p == null ? string.Empty : p + ":") + name.Name; } /// <summary> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |