Question

I'm having an issue with a report in SSRS (SQL Server 2008 R2). The problem happens regardless of if the input is provided from within report builder (v3) or via SSRS's web service interface.

Lets say this is the input XML (in a parameter called "ProvidedData"):

<person>
<name>joe</name>
</person>

...and I create a Dataset with the query:

<Query><XmlData>" & Parameters!ProvidedData.Value & "</XmlData>
<ElementPath>person</ElementPath></Query>

Then I create a field called "Name" with the field source "name". No problem - this can be usable on a report without any issue.

If I change the input XML to give it some namespace information it also works with no changes. So now the XML is:

<person xmlns:p="http://somenamespace">
<name>joe</name>
</person>

This also works - again, with no changes anywhere else. Works as a default value in Report Builder or when passed in from C# via the web service interface.

The problem is that I'm being fed XML with a default namespace and when I use that XML the field query doesn't resolve. No errors, it just doesn't find a value.

So if the XML is as follows, it doesn't work:

<person xmlns="http://somenamespace">
<name>joe</name>
</person>

Any ideas? I don't really have any control over the incoming XML so I'm stuck with the default namespace.

Was it helpful?

Solution

In the first two instances, the person element is actually a part of the default namespace (note that in the second, a prefix (p) is bound to the 'http://somenamespace' namespace, but the prefix is not assigned to person (as in p:person)).

In the last instance, the person element is actually bound to the namespace, so fully-qualified element is {http://somenamespace}person.

The appropriate query expression then requires the namespace to resolve the fully-qualified element, as in:

<Query xmlns:p="http://somenamespace">
 ...
<ElementPath>/p:person</ElementPath>
</Query>

Hope that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top