0
votes

I have below xml.

<prop:properties xmlns:prop="http://marklogic.com/xdmp/property">
  <cpf:processing-status xmlns:cpf="http://marklogic.com/cpf">done</cpf:processing-status>
  <cpf:property-hash xmlns:cpf="http://marklogic.com/cpf">6b9dab35ed148cd08bba59503892a0fd</cpf:property-hash>
  <cpf:last-updated xmlns:cpf="http://marklogic.com/cpf">2017-05-23T17:56:54.5734822+05:30</cpf:last-updated>
  <cpf:state xmlns:cpf="http://marklogic.com/cpf">http://marklogic.com/states/converted</cpf:state>
  <lnk:link from="/mycompany/mlabcNew_doc.xhtml" to="/mycompany/mlabcNew.doc" rel="source" rev="conversion" strength="strong" xmlns:lnk="http://marklogic.com/cpf/links"/>
  <cpf:self xmlns:cpf="http://marklogic.com/cpf">/mycompany/mlabcNew.doc</cpf:self>
</prop:properties>

i want to get the value of attribute 'to' (that is /mycompany/mlabcNew.doc) using java client API.

i have tried below structured query to fetch the result but didn't get the result

StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder();

    StructuredQueryDefinition query = qb.properties(
                qb.word(qb.elementAttribute(
                            qb.element(new QName("http://marklogic.com/cpf/links", "link")), 
                            qb.attribute(new QName("http://marklogic.com/cpf/links", "to"))), 
                        "/mycompany/mlabcNew_doc.xhtml"));

i didn't find the way to get this. please help

1

1 Answers

1
votes

The namespace of the attribute called 'to' is not the cpf/links namespace according to your sample.

Try:

StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder();

    StructuredQueryDefinition query = qb.properties(
                qb.word(qb.elementAttribute(
                            qb.element(new QName("http://marklogic.com/cpf/links", "link")), 
                            qb.attribute(new QName("", "to"))), 
                        "/mycompany/mlabcNew_doc.xhtml"));

Note: When troubleshooting this sort of thing, I usually confirm element and attribute names and namespaces in the Query Console using xPath. This removes many layers and makes troubleshooting more simple in some cases.