G
Guest
The method XmlDocument.SelectNodes does not behave properly in some situations
Here is the XML file with which the behavior reproduces
<VisualStudioProject><CSHAR
ProjectType = "Local
ProductVersion = "7.10.3077
SchemaVersion = "2.0
ProjectGuid = "{3CE6E417-5F92-42F9-A5F2-8710F577D686}
AssemblyKeyContainerName = "
AssemblyName = "ResxWrapWizard
AssemblyOriginatorKeyFile = "
DefaultClientScript = "JScript
DefaultHTMLPageLayout = "Grid
DefaultTargetSchema = "IE50
DelaySign = "false
OutputType = "WinExe
PreBuildEvent = "
PostBuildEvent = "
RootNamespace = "ResxWrapWizard
RunPostBuildEvent = "OnBuildSuccess
StartupObject = "
AllowUnsafeBlocks = "false
BaseAddress = "285212672
CheckForOverflowUnderflow = "false
ConfigurationOverrideFile = "
DefineConstants = "DEBUG;TRACE
DocumentationFile = "
DebugSymbols = "true
FileAlignment = "4096
IncrementalBuild = "false
NoStdLib = "false
NoWarn = "
Optimize = "false
OutputPath = "bin\Debug\
RegisterForComInterop = "false
RemoveIntegerChecks = "false
TreatWarningsAsErrors = "false
WarningLevel = "4
/><Confi
Name = "Release
AllowUnsafeBlocks = "false
BaseAddress = "285212672
CheckForOverflowUnderflow = "false
ConfigurationOverrideFile = "
DefineConstants = "TRACE
DocumentationFile = "
DebugSymbols = "false
FileAlignment = "4096
IncrementalBuild = "false
NoStdLib = "false
NoWarn = "
Optimize = "true
OutputPath = "bin\Release\
RegisterForComInterop = "false
RemoveIntegerChecks = "false
TreatWarningsAsErrors = "false
WarningLevel = "4
/></Settings><References><Referenc
Name = "System
AssemblyName = "System
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll
/><Referenc
Name = "System.Data
AssemblyName = "System.Data
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll
/><Referenc
Name = "System.Drawing
AssemblyName = "System.Drawing
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll
/><Referenc
Name = "System.Windows.Forms
AssemblyName = "System.Windows.Forms
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll
/><Referenc
Name = "System.XML
AssemblyName = "System.XML
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.XML.dll
/></References></Build><Files><Include><Fil
RelPath = "App.ico
BuildAction = "Content
/><Fil
RelPath = "AssemblyInfo.cs
BuildAction = "Compile
/><Fil
RelPath = "Form1.cs
SubType = "Form"
BuildAction = "Compile"
/><File
RelPath = "Form1.resx"
DependentUpon = "Form1.cs"
BuildAction = "EmbeddedResource"
/></Include></Files></CSHARP></VisualStudioProject>
Here is the code used to return all the nodes from that children of the "/VisualStudioProject/CSHARP/Files/Include":
XmlDocument projSettings = new XmlDocument();
projSettings.Load( "" );
XmlNode root = projSettings.SelectSingleNode( "/VisualStudioProject/CSHARP/Files/Include" );
foreach ( XmlNode sub in root.ChildNodes )
{
Console.WriteLine( sub.Name );
}
But instead of 4 nodes to be returned the following code returns only the very first node.
Also other attempts to retrive the other children nodes with XPath expressions like
XmlDocument.SelectNodes( "//File" ) return only the first node found in the XML file.
At the same time I tried to use the same file through Internet Explorer and query the same XPath expressions through XSLT and everything worked correctly. Thus I think the problem is neither in MS XML Parser nor in XPath expression.
Is there any idea what is wrong?
Here is the XML file with which the behavior reproduces
<VisualStudioProject><CSHAR
ProjectType = "Local
ProductVersion = "7.10.3077
SchemaVersion = "2.0
ProjectGuid = "{3CE6E417-5F92-42F9-A5F2-8710F577D686}
ApplicationIcon = "App.ico<Build><Setting
AssemblyKeyContainerName = "
AssemblyName = "ResxWrapWizard
AssemblyOriginatorKeyFile = "
DefaultClientScript = "JScript
DefaultHTMLPageLayout = "Grid
DefaultTargetSchema = "IE50
DelaySign = "false
OutputType = "WinExe
PreBuildEvent = "
PostBuildEvent = "
RootNamespace = "ResxWrapWizard
RunPostBuildEvent = "OnBuildSuccess
StartupObject = "
Name = "Debug<Confi
AllowUnsafeBlocks = "false
BaseAddress = "285212672
CheckForOverflowUnderflow = "false
ConfigurationOverrideFile = "
DefineConstants = "DEBUG;TRACE
DocumentationFile = "
DebugSymbols = "true
FileAlignment = "4096
IncrementalBuild = "false
NoStdLib = "false
NoWarn = "
Optimize = "false
OutputPath = "bin\Debug\
RegisterForComInterop = "false
RemoveIntegerChecks = "false
TreatWarningsAsErrors = "false
WarningLevel = "4
/><Confi
Name = "Release
AllowUnsafeBlocks = "false
BaseAddress = "285212672
CheckForOverflowUnderflow = "false
ConfigurationOverrideFile = "
DefineConstants = "TRACE
DocumentationFile = "
DebugSymbols = "false
FileAlignment = "4096
IncrementalBuild = "false
NoStdLib = "false
NoWarn = "
Optimize = "true
OutputPath = "bin\Release\
RegisterForComInterop = "false
RemoveIntegerChecks = "false
TreatWarningsAsErrors = "false
WarningLevel = "4
/></Settings><References><Referenc
Name = "System
AssemblyName = "System
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll
/><Referenc
Name = "System.Data
AssemblyName = "System.Data
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll
/><Referenc
Name = "System.Drawing
AssemblyName = "System.Drawing
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll
/><Referenc
Name = "System.Windows.Forms
AssemblyName = "System.Windows.Forms
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll
/><Referenc
Name = "System.XML
AssemblyName = "System.XML
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.XML.dll
/></References></Build><Files><Include><Fil
RelPath = "App.ico
BuildAction = "Content
/><Fil
RelPath = "AssemblyInfo.cs
BuildAction = "Compile
/><Fil
RelPath = "Form1.cs
SubType = "Form"
BuildAction = "Compile"
/><File
RelPath = "Form1.resx"
DependentUpon = "Form1.cs"
BuildAction = "EmbeddedResource"
/></Include></Files></CSHARP></VisualStudioProject>
Here is the code used to return all the nodes from that children of the "/VisualStudioProject/CSHARP/Files/Include":
XmlDocument projSettings = new XmlDocument();
projSettings.Load( "" );
XmlNode root = projSettings.SelectSingleNode( "/VisualStudioProject/CSHARP/Files/Include" );
foreach ( XmlNode sub in root.ChildNodes )
{
Console.WriteLine( sub.Name );
}
But instead of 4 nodes to be returned the following code returns only the very first node.
Also other attempts to retrive the other children nodes with XPath expressions like
XmlDocument.SelectNodes( "//File" ) return only the first node found in the XML file.
At the same time I tried to use the same file through Internet Explorer and query the same XPath expressions through XSLT and everything worked correctly. Thus I think the problem is neither in MS XML Parser nor in XPath expression.
Is there any idea what is wrong?