working with objects returned from evaluateXPath()
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 15
- Joined: Fri Jan 27, 2012 11:40 am
working with objects returned from evaluateXPath()
evaluateXPath() returns an array of Object. Exactly what object depends on the XPath expression but when the result is a sequence of nodes I seem to get classes from org.apache.xerces.dom. I'd like to use the appropriate methods on those objects.
Apparently evaluateXPath() returns objects that are not on the class path.
Do I need to add more to the class path?
Am I trying to do something evaluateXPath() was not intended to support?
Code: Select all
import org.apache.xerces.dom.*; // Compilte time error
...
WSXMLTextEditorPage xmlTep...
Object[] xpr = xmlTep.evaluateXPath(xp);
ws.showInformationMessage(xpr[0].getClass().getName()); // e.g. org.apache.xerces.dom.AttrImpl
String xprs = ((NodeImpl) xpr[0]).GetNodeValue(); // compile time error
Do I need to add more to the class path?
Am I trying to do something evaluateXPath() was not intended to support?
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: working with objects returned from evaluateXPath()
Hi,
The objects implement the DOM interface but some of them might not be the Xerces DOM implementations you are trying to cast them to.
You should try to cast the elements to the DOM interfaces like org.w3c.dom.Element or org.w3c.dom.Node or for example in your case to org.w3c.dom.Attr.
In this way, you do not need to worry about what DOM implementation they are (some of them might be special implementations of the DOM interfaces created by our code).
You should also check first that the received objects implement the proper interface like:
Regards,
Radu
The objects implement the DOM interface but some of them might not be the Xerces DOM implementations you are trying to cast them to.
You should try to cast the elements to the DOM interfaces like org.w3c.dom.Element or org.w3c.dom.Node or for example in your case to org.w3c.dom.Attr.
In this way, you do not need to worry about what DOM implementation they are (some of them might be special implementations of the DOM interfaces created by our code).
You should also check first that the received objects implement the proper interface like:
Code: Select all
if(xpr[0] instanceof org.w3c.dom.Attr){
String xprs = ((org.w3c.dom.Attr) xpr[0]).getValue();
}
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service