IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

Namespaces and XPath Options · View
mrmad
Posted: Friday, July 14, 2017 2:08:09 AM
Rank: Newbie

Joined: 7/14/2017
Posts: 3
Location: Australia
When trying to run an XPath across a message I am getting
"XPST0081: A namespace prefix used in an expression must be expandable into a namespace URI using the statically known namespaces"

Oddly the namespace is registered. The namespaces are registered inline as you work through the tree. Also the same Xpath works fine using other tools as well. Sample message below. Would like to eliminate my ignorance before considering this a bug.

Code:

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <ReadResponse xmlns="http://schemas.planview.com/PlanviewEnterprise/Services/QueryService/2012/12">
         <ReadResult xmlns:a="http://schemas.planview.com/PlanviewEnterprise/OpenSuite/OpenSuiteResult/2010/01/01" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:Failures xmlns:b="http://schemas.planview.com/PlanviewEnterprise/OpenSuite/OpenSuiteStatus/2010/01/01"/>
            <a:GeneralErrorMessage i:nil="true"/>
            <a:Successes xmlns:b="http://schemas.planview.com/PlanviewEnterprise/OpenSuite/OpenSuiteStatus/2010/01/01">
               <b:OpenSuiteStatus i:type="c:QueryStatus" xmlns:c="http://schemas.planview.com/PlanviewEnterprise/OpenSuite/QueryStatus/2012/12">
                  <b:Code i:nil="true"/>
                  <b:ErrorMessage i:nil="true"/>
                  <b:SourceIndex>0</b:SourceIndex>
                  <c:Dto xmlns:d="http://schemas.planview.com/PlanviewEnterprise/OpenSuite/Dtos/QueryDto/2012/12">
                     <d:ColumnNames xmlns:e="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                        <e:string>line_id</e:string>
                        <e:string>structure_code</e:string>
                        <e:string>amount</e:string>
                        <e:string>currency_code</e:string>
                        <e:string>account_code</e:string>
                        <e:string>last_updated_on</e:string>
                        <e:string>accountdescription</e:string>
                        <e:string>accountparentdescription</e:string>
                        <e:string>workId</e:string>
                        <e:string>projectName</e:string>
                        <e:string>note</e:string>
                        <e:string>line_attrib_code</e:string>
                        <e:string>line_attrib_value</e:string>
                        <e:string>lineattribDescr</e:string>
                        <e:string>epm_period_description</e:string>
                        <e:string>epm_year_description</e:string>
                        <e:string>period_id</e:string>
                        <e:string>version_id</e:string>
                        <e:string>versionDescription</e:string>
                     </d:ColumnNames>
                     <d:ColumnTypes xmlns:e="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                        <e:string>long</e:string>
                        <e:string>string</e:string>
                        <e:string>decimal</e:string>
                        <e:string>string</e:string>
                        <e:string>string</e:string>
                        <e:string>dateTime</e:string>
                        <e:string>string</e:string>
                        <e:string>string</e:string>
                        <e:string>string</e:string>
                        <e:string>string</e:string>
                        <e:string>string</e:string>
                        <e:string>string</e:string>
                        <e:string>string</e:string>
                        <e:string>string</e:string>
                        <e:string>string</e:string>
                        <e:string>long</e:string>
                        <e:string>long</e:string>
                        <e:string>long</e:string>
                        <e:string>string</e:string>
                     </d:ColumnTypes>
                     
                     <d:QueryResults xmlns:e="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                        <e:ArrayOfanyType>
                           <e:anyType i:type="f:long" xmlns:f="http://www.w3.org/2001/XMLSchema">119117</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">113352</e:anyType>
                           <e:anyType i:type="f:decimal" xmlns:f="http://www.w3.org/2001/XMLSchema">660000.00</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">AUD</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">3261</e:anyType>
                           <e:anyType i:type="f:dateTime" xmlns:f="http://www.w3.org/2001/XMLSchema">2017-05-29T10:51:32.253</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">Execution (CAPEX)</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">CAPEX</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">1025581</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">A given project</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema"/>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">Wbs777</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">11270</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">F2140_Unassigned - Somwehere</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">12</e:anyType>
                           <e:anyType i:type="f:long" xmlns:f="http://www.w3.org/2001/XMLSchema">2017</e:anyType>
                           <e:anyType i:type="f:long" xmlns:f="http://www.w3.org/2001/XMLSchema">215</e:anyType>
                           <e:anyType i:type="f:long" xmlns:f="http://www.w3.org/2001/XMLSchema">165</e:anyType>
                           <e:anyType i:type="f:string" xmlns:f="http://www.w3.org/2001/XMLSchema">Some comment</e:anyType>
                        </e:ArrayOfanyType>
                       
                     </d:QueryResults>
                     
                  </c:Dto>
               </b:OpenSuiteStatus>
            </a:Successes>
            <a:Warnings xmlns:b="http://schemas.planview.com/PlanviewEnterprise/OpenSuite/OpenSuiteStatus/2010/01/01"/>
         </ReadResult>
      </ReadResponse>
   </s:Body>
</s:Envelope>
island
Posted: Friday, July 14, 2017 6:13:40 AM
Rank: Newbie

Joined: 10/28/2002
Posts: 1,283
Location: AT
It would be helpful to know

a) what the actual XPath statement that you are trying to execute is.
b) what options have been set in the XPath Evaluator window.
mrmad
Posted: Friday, July 14, 2017 7:51:36 AM
Rank: Newbie

Joined: 7/14/2017
Posts: 3
Location: Australia
island wrote:
It would be helpful to know

a) what the actual XPath statement that you are trying to execute is.
b) what options have been set in the XPath Evaluator window.


a) Expression example: /s:Envelope/s:Body/ReadResponse/ReadResult/a:Successes/b:OpenSuiteStatus/c:Dto/d:QueryResults/e:ArrayOfanyType/e:anyType[3]

b) default values (fresh install of 2017), tried Xpath 1/2 & 3.1
vlad
Posted: Friday, July 14, 2017 8:56:56 AM
Rank: Advanced Member

Joined: 12/13/2005
Posts: 2,856
Location: Mauritius
This is because you define namespace prefixes within the document. It has to be assumed that they can change from node to node, and therefore such prefixes cannot be used. Only those assignments on the very top of your document (in your case prefix s) are considered as stable.

Now, this is how the XPath box works. Depending on your needs you have at least two workarounds:

1. If all you need is to execute statement and see results, then you can switch to XQuery 3.1 execution from XPath. XQuery is a superset of XPath and allows few more commands, like definition of namespaces:

declare namespace a = "http://schemas.planview.com/PlanviewEnterprise/OpenSuite/OpenSuiteResult/2010/01/01";
declare namespace b = "http://schemas.planview.com/PlanviewEnterprise/OpenSuite/OpenSuiteStatus/2010/01/01";
declare namespace c = "http://schemas.planview.com/PlanviewEnterprise/OpenSuite/QueryStatus/2012/12";
declare namespace d = "http://schemas.planview.com/PlanviewEnterprise/OpenSuite/Dtos/QueryDto/2012/12";
declare namespace e = "http://schemas.microsoft.com/2003/10/Serialization/Arrays";
/s:Envelope/s:Body/ReadResponse/ReadResult/a:Successes/b:OpenSuiteStatus/c:Dto/d:QueryResults/e:ArrayOfanyType/e:anyType[3]

2. When transforming documents, XPath is usually used within XSLT file. There you have a chance to declare namespace prefixes before actually executing your statement.
mrmad
Posted: Monday, July 17, 2017 1:22:45 AM
Rank: Newbie

Joined: 7/14/2017
Posts: 3
Location: Australia
vlad wrote:
This is because you define namespace prefixes within the document. It has to be assumed that they can change from node to node, and therefore such prefixes cannot be used. Only those assignments on the very top of your document (in your case prefix s) are considered as stable.

Now, this is how the XPath box works. Depending on your needs you have at least two workarounds:

1. If all you need is to execute statement and see results, then you can switch to XQuery 3.1 execution from XPath. XQuery is a superset of XPath and allows few more commands, like definition of namespaces:

declare namespace a = "http://schemas.planview.com/PlanviewEnterprise/OpenSuite/OpenSuiteResult/2010/01/01";
declare namespace b = "http://schemas.planview.com/PlanviewEnterprise/OpenSuite/OpenSuiteStatus/2010/01/01";
declare namespace c = "http://schemas.planview.com/PlanviewEnterprise/OpenSuite/QueryStatus/2012/12";
declare namespace d = "http://schemas.planview.com/PlanviewEnterprise/OpenSuite/Dtos/QueryDto/2012/12";
declare namespace e = "http://schemas.microsoft.com/2003/10/Serialization/Arrays";
/s:Envelope/s:Body/ReadResponse/ReadResult/a:Successes/b:OpenSuiteStatus/c:Dto/d:QueryResults/e:ArrayOfanyType/e:anyType[3]

2. When transforming documents, XPath is usually used within XSLT file. There you have a chance to declare namespace prefixes before actually executing your statement.


Using XQuery nailed it for me once I also added a default namespace, though more effort than expected for the simple use case I normally use XPath for. Saying that, it is a pretty crummy XML response we get from that service.
Thanks.
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.