-
-
Notifications
You must be signed in to change notification settings - Fork 725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XmlPeek not working correctly for element nodes #1537
Comments
[Proposal for a Bugfix]After some investigation I found the bug. Have a look at line cake/src/Cake.Common/Xml/XmlPeekAliases.cs Line 141 in 303b1d0
When calling method This does not happen if you are using an Here the corrected code: /// <summary>
/// Gets the value of a target node.
/// </summary>
/// <returns>The value found at the given XPath query (or the first, if multiple eligible nodes are found).</returns>
/// <param name="source">The xml to peek into.</param>
/// <param name="xpath">The xpath of the single node to get.</param>
/// <param name="settings">Additional settings to tweak Xml Peek behavior.</param>
private static string XmlPeek(XmlReader source, string xpath, XmlPeekSettings settings)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
if (string.IsNullOrWhiteSpace(xpath))
{
throw new ArgumentNullException(nameof(xpath));
}
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
var document = new XmlDocument();
document.PreserveWhitespace = settings.PreserveWhitespace;
document.Load(source);
var navigator = document.CreateNavigator();
XmlNamespaceManager namespaceManager = null;
if (navigator.NameTable != null)
{
namespaceManager = new XmlNamespaceManager(navigator.NameTable);
foreach (var xmlNamespace in settings.Namespaces)
{
namespaceManager.AddNamespace(xmlNamespace.Key /* Prefix */, xmlNamespace.Value /* URI */);
}
}
var node = navigator.SelectSingleNode(xpath, namespaceManager);
return node?.Value;
} Hint:Have a look at the XML doc comments in this file - some are misleading. For the method above I already corrected the comments. |
I have just updated to Cake version 0.21.1 and it is still happening. Any estimation about when this will be fixed? Thanks! |
Currently I don't have time to drop a pull request, but the code I posted above fixes the issue. Maybe some of the Cake guys can take the code snippet and fix that bug. ;-) |
… handle retrieval of element values; add supporting tests
… handle retrieval of element values; add supporting tests
… handle retrieval of element values; add supporting tests
… handle retrieval of element values; add supporting tests
… handle retrieval of element values; add supporting tests
fixed by #1701 |
What You Are Seeing?
I have the following XML document:
The following code does not yield the
publishUrl
element (insteadnull
ist returned and a warning is logged):Running the same code using the standard .NET
XPathDocument
works okay.What is Expected?
XmlPeek
should return the contents of thepublishUrl
element, i.e.C:\Deployment\DeploymentTemplate\WebApi
.When using
XPathDocument
everything works okay:Here
node
contains the selected node.What version of Cake are you using?
Version 0.17.0
Are you running on a 32 or 64 bit system?
64bit
What environment are you running on? Windows? Linux? Mac?
Windows
How Did You Get This To Happen? (Steps to Reproduce)
See code above.
The text was updated successfully, but these errors were encountered: