0

I'm relatively new to XQuery and I'm using a XML with the following format (MODSXML):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<modsCollection xmlns="http://www.loc.gov/mods/v3" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                  xsi:schemaLocation="http://www.loc.gov/mods/v3 
                 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd">

<mods ID="ISI:000330282600027" version="3.0">
<titleInfo>
<title>{Minimum Relative Entropy for Quantum Estimation: Feasibility and General
 Solution}</title>
</titleInfo>

I'm trying to retrieva all titles of the articles contained on the XML file. The expression I'm using is the following:

for $x in collection("ExemploBibtex")/"quantuminformation.xml"/modsCollection/mods/titleInfo/title
return <title>$x/text()</title>

When I try to run this expression on Base, I get the following error:

"[XPTY0019] Steps within a path expression must yield nodes; xs:string found."

Can anybody tell me what's wrong? The result I was expecting was a list with all the titles in the document.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96

2 Answers2

1

Okay, problem solved in the BaseX Mailing List :D

I needed to declare the namespace. So now I'm using:

declare namespace v3 ="http://www.loc.gov/mods/v3";
for $doc in collection('ExemploBibtex')
    where matches(document-uri($doc), 'quantuminformation.xml')
return $doc/v3:modsCollection/v3:mods/v3:titleInfo/v3:title/text()

And it works.

0

The problem is here:

collection("ExemploBibtex")/"quantuminformation.xml"/modsCollection

This returns a string with content quantuminformation.xml for each file/root node in the ExemploBibtex collection, and then tries to perform an axis step on each of these strings -- which is not allowed.

It seems you want to access to document quantuminformation.xml within the collection ExemploBibtex. To open a specific file of a collection, use following syntax instead:

collection("ExemploBibtex/quantuminformation.xml")/modsCollection

I cut of the last axis steps for readability and keeping the code lines short; simply add them again, they're fine.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96