..NETters,
This may be a simple question. However, I cannot figure out what I am
doing wrong. Would appreciate if someone can help me.
Here is my Sample.xml:
<Report>
</Report>
Here is my code to read it:
XmlDocument doc = new XmlDocument();
doc.Load("Sample.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr = nav.Compile("Report");
XPathNodeIterator iter = nav.Select(expr);
while(iter.MoveNext()) {
Console.WriteLine(iter.Current.Name);
}
In this case, the output is what I expect.
Now, I modified my xml file and added a namespace as follows:
<Report
xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition">
</Report>
My earlier code does not work after this point. The node iterator does
not return any matching nodes. This is expected.
To fix this, I added the namespace manager object as follows:
XmlDocument doc = new XmlDocument();
doc.Load("Sample.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr = nav.Compile("Report");
// BEGIN INSERT NEW CODE
XmlNamespaceManager mngr = new XmlNamespaceManager(doc.NameTable);
mngr.AddNamespace("",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
expr.SetContext(mngr);
// END INSERT NEW CODE
XPathNodeIterator iter = nav.Select(expr);
while(iter.MoveNext()) {
Console.WriteLine(iter.Current.Name);
}
The node iterator still does not return any matching nodes.
Can someone please enlighten me on what is my mistake?
Thank you in advance for your help.
Pradeep 9 1911
Hello Pradeep,
You need to use a prefix when querying xml with xpath even if the xml is in the default namespace.
Try changing the following code...
XPathExpression expr = nav.Compile("/default:Report");
mngr.AddNamespace("default",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
That should hopefully work now. I'm assuming the Report element is the root of the document as your xml wasn't displayed in your post.
---
Posted via DotNetSlackers.com
Hello Pradeep,
You need to use a prefix when querying xml with xpath even if the xml is in the default namespace.
Try changing the following code...
XPathExpression expr = nav.Compile("/default:Report");
mngr.AddNamespace("default",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
That should hopefully work now. I'm assuming the Report element is the root of the document as your xml wasn't displayed in your post.
---
Posted via DotNetSlackers.com
Hello Pradeep,
You need to use a prefix when querying xml with xpath even if the xml is in the default namespace.
Try changing the following code...
XPathExpression expr = nav.Compile("/default:Report");
mngr.AddNamespace("default",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
That should hopefully work now. I'm assuming the Report element is the root of the document as your xml wasn't displayed in your post.
---
Posted via DotNetSlackers.com
Hello Pradeep,
You need to use a prefix when querying xml with xpath even if the xml is in the default namespace.
Try changing the following code...
XPathExpression expr = nav.Compile("/default:Report");
mngr.AddNamespace("default",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
That should hopefully work now. I'm assuming the Report element is the root of the document as your xml wasn't displayed in your post.
---
Posted via DotNetSlackers.com
Hello Pradeep,
You need to use a prefix when querying xml with xpath even if the xml is in the default namespace.
Try changing the following code...
XPathExpression expr = nav.Compile("/default:Report");
mngr.AddNamespace("default",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
That should hopefully work now. I'm assuming the Report element is the root of the document as your xml wasn't displayed in your post.
---
Posted via DotNetSlackers.com
Hello Pradeep,
You need to use a prefix when querying xml with xpath even if the xml is in the default namespace.
Try changing the following code...
XPathExpression expr = nav.Compile("/default:Report");
mngr.AddNamespace("default",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
That should hopefully work now. I'm assuming the Report element is the root of the document as your xml wasn't displayed in your post.
---
Posted via DotNetSlackers.com
Hello Pradeep,
You need to use a prefix when querying xml with xpath even if the xml is in the default namespace.
Try changing the following code...
XPathExpression expr = nav.Compile("/default:Report");
mngr.AddNamespace("default",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
That should hopefully work now. I'm assuming the Report element is the root of the document as your xml wasn't displayed in your post.
---
Posted via DotNetSlackers.com
Hello Pradeep,
You need to use a prefix when querying xml with xpath even if the xml is in the default namespace.
Try changing the following code...
XPathExpression expr = nav.Compile("/default:Report");
mngr.AddNamespace("default",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
That should hopefully work now. I'm assuming the Report element is the root of the document as your xml wasn't displayed in your post.
---
Posted via DotNetSlackers.com
Hello Pradeep,
You need to use a prefix when querying xml with xpath even if the xml is in the default namespace.
Try changing the following code...
XPathExpression expr = nav.Compile("/default:Report");
mngr.AddNamespace("default",
"http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
That should hopefully work now. I'm assuming the Report element is the root of the document as your xml wasn't displayed in your post.
---
Posted via DotNetSlackers.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: BCC |
last post by:
Hi,
I have a tab separated value table like this:
header1 header2 header3
13.455 55.3 A string
4.55 5.66 Another string
I want to load this guy...
|
by: Dave Griffin |
last post by:
This is a followup to my question in doing unmanaged DLLs in .NET. I
was able to create the DLL and the application was able to see it. So
far so good. Now I need to make that unmanaged DLL read an...
|
by: DjordjeD |
last post by:
I need to call(reference) class member
"PrintDestination.PrintDestinationPrinter" from another file. How do I
do it, I tried
"ReportRenderer.PrintDestination.PrintDestinationPrinter" but it...
|
by: vkrasner |
last post by:
It works with VS2003 and does not in VS2005:
in VS2003 :
string sMyvalue = ConfigurationSettings.AppSettings;
in VS2005 (does not work!!)
string sMyvalue = ConfigurationManager.AppSettings;
...
|
by: Antonio Tirado |
last post by:
Hi,
I'm using the OleDB namespace to open a CSV File. I can read the file
sucessfully except for hyphenated values. My CSV File contains phone numbers
and sometimes these come separated with...
| |
by: =?Utf-8?B?TWlrZQ==?= |
last post by:
Hi. Is it programatically possible in VB.NET to read the contents of
web.config's <customErrorselement? I looked at using
ConfigurationSettings.AppSettings, but that doesn't work.
I need to...
|
by: sheriff |
last post by:
Dear friends,
im a newbee for this forum and c++ im doing my MSc in Simulation Tech in mech. Engineering. My knowledge of c++ is very little which I had during my UG studies Long long ago .I am...
|
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= |
last post by:
I want to open a text file and format it into a specific line and then apply
color to a specific location of the text and then display it in a RichTextBox
after all of this is done.
I can do all...
|
by: dm3281 |
last post by:
Hello, I have a text report from a mainframe that I need to parse.
The report has about a 2580 byte header that contains binary information
(garbage for the most part); although there are a...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |