Hi Group,
i now tried the first time the new (since Xerces 2.4.0 i think) XPath
Interface. But with no big success :-(. I can't find a sample or figure
out what i'm doing wrong. So i kindly ask for your help. Other Xerces
DOM stuff works like charm (i parse this XML-Document and change some
elements/attributes a.s.o.). I am using Microsoft Visual Studio 6.0 and
Xerces 2.4.0. Windows-binaries package from xml.apache site.
The Problem:
------------
I have to get some (selected, wide spread over the whole XML-File)
attribute-values from within a bigger XML file. So i think a XPath is
the best for that, isn't it? I wrote a little Testsnippet to try it out.
Here is what i've done so far:
--------------------SNIP-----------------------
// Note: X() is a macro for transcoding char to XMLChar
// X2C() is the reverse macro for transcoding XMLChar to Char
DOMImplementation *impl;
DOMXPathResult *xpres;
DOMBuilder *builder;
DOMDocument *doc;
DOMXPathEvaluator *xpeval;
char tmpbuf[1024];
// Initialize XERCES DOM
impl = dom_Init();
builder = ((DOMImplementationLS*) impl)->
createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
doc = builder->parseURI(X("./testdata/test_105.xml"));
xpeval = (DOMXPathEvaluator *) doc;
try
{
xpres = (DOMXPathResult *)
xpeval->evaluate(X("/cdh/id/@RT"),
doc->getDocumentElement(),
NULL, DOMXPathResult::STRING_TYPE, NULL);
}
catch(const DOMXPathException& xp)
{
sprintf(tmpbuf, "Exception Code: %d", xp.code);
MessageBox(NULL, tmpbuf, "XPathException", MB_OK);
}
catch(const DOMException& de)
{
sprintf(tmpbuf, "Exception Code: %d", de.code);
MessageBox(NULL, tmpbuf, "DOMException", MB_OK);
}
sprintf(tmpbuf, "<%s>", X2C(xpres->getStringValue()));
MessageBox(NULL, tmpbuf, "XPathTest", MB_OK);
builder->releas();
dom_DeInit();
--------------------SNIP-----------------------
The XML-File is like this (only the relevant part):
--------------------SNIP-----------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="sci_arztbrief-2.xsl"?>
<levelone xmlns="urn::hl7-org/cda"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sciphox="urn::sciphox-org/sciphox"
xsi:schemaLocation="urn::hl7-org/cda sciphox-cda.xsd">
<cdh>
<id RT="#cdh.docid.rt" EX="#cdh.docid.ex"/>
<set_id RT="#cdh.docsetid.rt" EX="#cdh.docsetid.ex"/>
<version_nbr V="#cdh.docvers"/>
... blah blah blah
</cdh>
... blah blah blah
</levelone>
--------------------SNIP-----------------------
I want to get the Value of the RT Attribute from the ID-Element within
the cdh element. I want to get "#cdh.docid.rt" as the result.
But i only get a DOMException Code 9 (Not supported) which meaning is
either the context node is not valid or the type is not supported by the
DOMXPathEvaluator. I don't understand what this could mean in my case.
Any hint, sample, documentation appreciated. Thanks in Advance very
much. Oh...and by the way...it is a little bit urgent. So if you can
afford time a "asap" answer would help me muuuuuuch.
CU
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]