How standardized is the "@" notation in XPath?

C

Cambridge Ray

I have several GUI XML utilities (Stylus $tudio, BaseX61) which deal
nicely with the "@" notation for attributes. However, when I tried to
use it with the Xerces-C library, it crashed.

TIA,

-RFH
 
M

Martin Honnen

Cambridge said:
I have several GUI XML utilities (Stylus $tudio, BaseX61) which deal
nicely with the "@" notation for attributes. However, when I tried to
use it with the Xerces-C library, it crashed.

XPath 1.0 defines the attribute axis and @ as a shortcut to use it, see
http://www.w3.org/TR/xpath/#path-abbrev

Does Xerces implement XPath? Isn't that Xalan's job in the toolset of
XML tools Apache provides? Or are you using some xpath in a schema?
 
J

Joe Kesselman

XPath 1.0 defines the attribute axis and @ as a shortcut to use it, see
http://www.w3.org/TR/xpath/#path-abbrev

Does Xerces implement XPath? Isn't that Xalan's job in the toolset of
XML tools Apache provides? Or are you using some xpath in a schema?

Yes, and that's correct, and what is the querant actually trying to do?
It's more likely that you're misusing something than that you've found a
bug in the Apache tools, but bugs are certainly possible.


--
Joe Kesselman,
http://www.love-song-productions.com/people/keshlam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
 
C

Cambridge Ray

XPath 1.0 defines the attribute axis and @ as a shortcut to use it, seehttp://www.w3.org/TR/xpath/#path-abbrev
Does Xerces implement XPath?

Yes, it does. I was provided the code below by one of Xerces' authors,
Alberto Massari.

-Ramon

---------------------
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <iostream>

using namespace std;

main(int argc, char *argv[])
{

try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
char *pMessage = XMLString::transcode(toCatch.getMessage());
fprintf(stderr, "Error during initialization! \n %s \n",
pMessage);
XMLString::release(&pMessage);
return -1;
}
XercesDOMParser parser;
parser.parse("simple-sample.xml");
DOMDocument *document = parser.getDocument();
XMLCh xpathStr[100];

XMLString::transcode("/line-segments/horizontal/distance",
xpathStr, sizeof(xpathStr) - 1);

DOMXPathResult* result = (DOMXPathResult*)document->evaluate
(xpathStr,
(const xercesc_3_1::DOMNode*)document->getDocumentElement(),
NULL,
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
NULL);

int count = result->getSnapshotLength();
for (int i = 0; i < count; i++) {
result->snapshotItem(i); // this selects the node for the
getNodeValue call
DOMNode* item = result->getNodeValue();
cout << "item #" << i+1 << ": `" << XMLString::transcode(item-
getTextContent()) << "'" << endl;
// do something with the item->getTextContent()
}
result->release();
return 0;
}
 
C

Cambridge Ray

Yes, it does.

Ooops, I guess XPath is more complex than a simple slash-separated set
of elements.

Correction: Xerces provides a minimum XPath implementation, through
the document->evaluate() member function. I guess that answers the
question in the OP.

-Ramon
 
J

Joe Kesselman

Ooops, I guess XPath is more complex than a simple slash-separated set
of elements.

Yes, it is.

A complete XPath 1.0 implementation that works with Xerces is available
from Apache, as part of the Xalan package (which also supports the XSLT
transformation/stylesheet language, which uses XPath).

--
Joe Kesselman,
http://www.love-song-productions.com/people/keshlam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top