Project

Profile

Help

ClassCastException: TinyElementImpl

Added by Anonymous about 16 years ago

Legacy ID: #4988991 Legacy Poster: EvdS (esteen)

I get a classcast exception on line 4 of the following code: StringReader reader = new StringReader(xml); org.xml.sax.InputSource inputSource = new InputSource(reader); javax.xml.xpath.XPath xpath = XPathFactory.newInstance().newXPath(); org.w3c.dom.Node n = (Node) xpath.evaluate(xpathExpressionStr, inputSource, XPathConstants.NODE); -> java.lang.ClassCastException: net.sf.saxon.tinytree.TinyElementImpl I'm using saxon9 for implementation. Can anybody tell me how to avoid this classcast exception?


Replies (4)

Please register to reply

RE: ClassCastException: TinyElementImpl - Added by Anonymous about 16 years ago

Legacy ID: #4989015 Legacy Poster: EvdS (esteen)

I forget to enclose the actual xml and xpath expression. Expression: //assessmentSection[@id='218'] XML: <?xml version="1.0"?> <assessments> <assessment id="101" customerid="FNWI" identifier="FNWI" startdate="30-06-2008 00:00" startdateOrdered="2008-06-30 00:00"> <title contentCode="im030000_content_1554"> <text language="nl">Intakeformulier FNWI</text> </title> <metadata/> <assessmentSection id="210" identifier="im030000_section_210" type="form" order="3"> <title contentCode="im030000_content_1557"> <text language="nl">Opleiding</text> </title> <explanation contentCode="im030000_content_1558"> <text language="nl">&lt;br type=&quot;_moz&quot; /&gt;</text> </explanation> <assessmentSection id="218" identifier="im030000_section_218" type="set" order="2"> <title contentCode="im030000_content_1653"> <text language="nl">Vooropleiding</text> </title> <explanation contentCode="im030000_content_1654"> <text language="nl">Vul hier informatie in over je vooropleiding. Alle velden gemarkeerd met * zijn verplicht.</text> </explanation> <assessmentItem identifier="imanswer_educationFNWI" shortname="Vooropleiding FNWI" id="442" itemidentifier="im030000_item_442" basetype="string" rendertype="radiolist" cardinality="multiple" order="2" focus="1" required="1" labelposition="top" hidden="0"> <title contentCode="content07_06_05206"> <text language="nl">Op grond van welke vooropleiding heb je toegang tot de opleiding?</text> </title> <aliasTitle contentCode="im030000_content_1657"> <text language="nl"/> </aliasTitle> <aliasExplanation contentCode="im030000_content_1658"> <text language="nl"/> </aliasExplanation> <defaultvalue contentCode="im030000_content_1659"> <text language="nl"/> </defaultvalue> <itemformats contentCode="imanswer_educationFNWI_format"/> <interaction interactionType="choiceInteraction" identifier="vooropleidingFNWIInteraction" maxchoice="1"> <simpleChoice id="vooropleidingFNWI_1" isdefault="0" order="1"> <text language="nl">Diploma VWO</text> </simpleChoice> <simpleChoice id="vooropleidingFNWI_10" isdefault="0" order="9"> <text language="nl">Beschikking College van Bestuur</text> </simpleChoice> <simpleChoice id="vooropleidingFNWI_2" isdefault="0" order="2"> <text language="nl">Diploma Gymnasium</text> </simpleChoice> <simpleChoice id="vooropleidingFNWI_3" isdefault="0" order="3"> <text language="nl">Diploma HBO propedeuse</text> </simpleChoice> <simpleChoice id="vooropleidingFNWI_4" isdefault="0" order="4"> <text language="nl">Diploma Afgeronde HBO opleiding</text> </simpleChoice> <simpleChoice id="vooropleidingFNWI_5" isdefault="0" order="5"> <text language="nl">Diploma Afgeronde Universitaire opleiding</text> </simpleChoice> <simpleChoice id="vooropleidingFNWI_6" isdefault="0" order="6"> <text language="nl">Diploma Buitenlandse vooropleiding</text> </simpleChoice> <simpleChoice id="vooropleidingFNWI_7" isdefault="0" order="10"> <text language="nl">Anders</text> </simpleChoice> <simpleChoice id="vooropleidingFNWI_8" isdefault="0" order="7"> <text language="nl">Colloquium doctum</text> </simpleChoice> <simpleChoice id="vooropleidingFNWI_9" isdefault="0" order="8"> <text language="nl">Betabrug-traject</text> </simpleChoice> </interaction> <condition/> </assessmentItem> <assessmentItem identifier="imanswer_educationHBOpropedeuse" shortname="HBO Propedeuse" id="443" itemidentifier="im030000_item_443" basetype="string" rendertype="text" cardinality="single" order="3" focus="0" required="1" labelposition="top" hidden="0"> <title contentCode="content04_02_0358"> <text language="nl">Welke HBO propedeuse</text> </title> <aliasTitle contentCode="im030000_content_1660"> <text language="nl"/> </aliasTitle> <aliasExplanation contentCode="im030000_content_1661"> <text language="nl"/> </aliasExplanation> <defaultvalue contentCode="im030000_content_1662"> <text language="nl"/> </defaultvalue> <itemformats contentCode="imanswer_educationHBOpropedeuse_format"/> <interaction interactionType="stringInteraction" identifier="stringInteraction04_02_0358" maxchoice="1"/> <condition operator="=" associatedIdentifier="imanswer_educationFNWI" itemid="442" outcome="vooropleidingFNWI_3"/> </assessmentItem> <assessmentItem identifier="imanswer_educationHBOdiploma" shortname="HBO Propedeuse diploma behaald" id="444" itemidentifier="im030000_item_444" basetype="string" rendertype="text" cardinality="single" order="4" focus="0" required="1" labelposition="top" hidden="0"> <title contentCode="content04_02_0459"> <text language="nl">Welke HBO opleiding</text> </title> <aliasTitle contentCode="im030000_content_1663"> <text language="nl"/> </aliasTitle> <aliasExplanation contentCode="im030000_content_1664"> <text language="nl"/> </aliasExplanation> <defaultvalue contentCode="im030000_content_1665"> <text language="nl"/> </defaultvalue> <itemformats contentCode="imanswer_educationHBOdiploma_format"/> <interaction interactionType="stringInteraction" identifier="stringInteraction04_02_0459" maxchoice="1"/> <condition operator="=" associatedIdentifier="imanswer_educationFNWI" itemid="442" outcome="vooropleidingFNWI_4"/> </assessmentItem> <assessmentItem identifier="imanswer_educationOther" shortname="Vooropleiding anders" id="445" itemidentifier="im030000_item_445" basetype="string" rendertype="text" cardinality="single" order="5" focus="0" required="1" labelposition="top" hidden="0"> <title contentCode="content04_01_0248"> <text language="nl">... Indien anders, welke?</text> </title> <aliasTitle contentCode="im030000_content_1666"> <text language="nl"/> </aliasTitle> <aliasExplanation contentCode="im030000_content_1667"> <text language="nl"/> </aliasExplanation> <defaultvalue contentCode="im030000_content_1668"> <text language="nl"/> </defaultvalue> <itemformats contentCode="imanswer_educationOther_format"/> <interaction interactionType="stringInteraction" identifier="stringInteraction04_01_0248" maxchoice="1"/> <condition operator="=" associatedIdentifier="imanswer_educationFNWI" itemid="442" outcome="vooropleidingFNWI_1"/> </assessmentItem> <assessmentItem identifier="imanswer_educationStudyhome" shortname="Studiehuis diploma" id="446" itemidentifier="im030000_item_446" basetype="string" rendertype="radiolist" cardinality="multiple" order="6" focus="0" required="1" labelposition="top" hidden="0"> <title contentCode="content04_02_0560"> <text language="nl">Heb je een VWO diploma van voor het studiehuis?</text> </title> <aliasTitle contentCode="im030000_content_1669"> <text language="nl"/> </aliasTitle> <aliasExplanation contentCode="im030000_content_1670"> <text language="nl"/> </aliasExplanation> <defaultvalue contentCode="im030000_content_1671"> <text language="nl"/> </defaultvalue> <itemformats contentCode="imanswer_educationStudyhome_format"/> <interaction interactionType="choiceInteraction" identifier="yesnoInteraction" maxchoice="1"> <simpleChoice id="yesno_1" isdefault="0" order="1"> <text language="nl">Ja</text> </simpleChoice> <simpleChoice id="yesno_2" isdefault="0" order="2"> <text language="nl">Nee</text> </simpleChoice> </interaction> <condition/> </assessmentItem> <assessmentItem identifier="imanswer_educationVWOExamProgram" shortname="Studiehuis vakkenpakket" id="447" itemidentifier="im030000_item_447" basetype="string" rendertype="checkboxlist" cardinality="multiple" order="7" focus="0" required="1" labelposition="top" hidden="0"> <title contentCode="content04_02_0661"> <text language="nl">Welke vakken zaten in je examenprogramma?</text> </title> <aliasTitle contentCode="im030000_content_1672"> <text language="nl"/> </aliasTitle> <aliasExplanation contentCode="im030000_content_1673"> <text language="nl"/> </aliasExplanation> <defaultvalue contentCode="im030000_content_1674"> <text language="nl"/> </defaultvalue> <itemformats contentCode="imanswer_educationVWOExamProgram_format"/> <interaction interactionType="choiceInteraction" identifier="examenprogrammaInteraction" maxchoice="0"> <simpleChoice id="examenprogramma_1" isdefault="0" order="1"> <text language="nl">Natuurkunde</text> </simpleChoice> <simpleChoice id="examenprogramma_2" isdefault="0" order="2"> <text language="nl">Scheikunde</text> </simpleChoice> <simpleChoice id="examenprogramma_3" isdefault="0" order="3"> <text language="nl">Wiskunde A</text> </simpleChoice> <simpleChoice id="examenprogramma_4" isdefault="0" order="4"> <text language="nl">Wiskunde B</text> </simpleChoice> <simpleChoice id="examenprogramma_5" isdefault="0" order="5"> <text language="nl">Biologie</text> </simpleChoice> </interaction> <condition operator="=" associatedIdentifier="imanswer_educationStudyhome" itemid="446" outcome="yesno_1"/> </assessmentItem> <assessmentItem identifier="imanswer_educationVWOProfile" shortname="Studiehuis profiel" id="448" itemidentifier="im030000_item_448" basetype="string" rendertype="radiolist" cardinality="multiple" order="8" focus="0" required="1" labelposition="top" hidden="0"> <title contentCode="content04_02_0762"> <text language="nl">Wat was je profiel?</text> </title> <aliasTitle contentCode="im030000_content_1675"> <text language="nl"/> </aliasTitle> <aliasExplanation contentCode="im030000_content_1676"> <text language="nl"/> </aliasExplanation> <defaultvalue contentCode="im030000_content_1677"> <text language="nl"/> </defaultvalue> <itemformats contentCode="imanswer_educationVWOProfile_format"/> <interaction interactionType="choiceInteraction" identifier="profielInteraction" maxchoice="1"> <simpleChoice id="profiel_1" isdefault="0" order="1"> <text language="nl">Natuur en Techniek</text> </simpleChoice> <simpleChoice id="profiel_2" isdefault="0" order="2"> <text language="nl">Natuur- en Gezondheid</text> </simpleChoice> <simpleChoice id="profiel_3" isdefault="0" order="3"> <text language="nl">Economie en Maatschappij</text> </simpleChoice> <simpleChoice id="profiel_4" isdefault="0" order="4"> <text language="nl">Cultuur en Maatschappij</text> </simpleChoice> </interaction> <condition operator="=" associatedIdentifier="imanswer_educationStudyhome" itemid="446" outcome="yesno_2"/> </assessmentItem> <assessmentItem identifier="imanswer_educationVWOProfileParts" shortname="Studiehuis profiel onderdelen" id="449" itemidentifier="im030000_item_449" basetype="string" rendertype="checkboxlist" cardinality="multiple" order="9" focus="0" required="1" labelposition="top" hidden="0"> <title contentCode="content04_02_0863"> <text language="nl">Onderdelen in je profiel:</text> </title> <aliasTitle contentCode="im030000_content_1678"> <text language="nl"/> </aliasTitle> <aliasExplanation contentCode="im030000_content_1679"> <text language="nl"/> </aliasExplanation> <defaultvalue contentCode="im030000_content_1680"> <text language="nl"/> </defaultvalue> <itemformats contentCode="imanswer_educationVWOProfileParts_format"/> <interaction interactionType="choiceInteraction" identifier="profielonderdelenInteraction" maxchoice="0"> <simpleChoice id="profielonderdelen_1" isdefault="0" order="1"> <text language="nl">Natuurkunde 1</text> </simpleChoice> <simpleChoice id="profielonderdelen_2" isdefault="0" order="2"> <text language="nl">Natuurkunde 2</text> </simpleChoice> <simpleChoice id="profielonderdelen_3" isdefault="0" order="3"> <text language="nl">Scheikunde 1</text> </simpleChoice> <simpleChoice id="profielonderdelen_4" isdefault="0" order="4"> <text language="nl">Scheikunde 2</text> </simpleChoice> <simpleChoice id="profielonderdelen_5" isdefault="0" order="5"> <text language="nl">Wiskunde 1</text> </simpleChoice> <simpleChoice id="profielonderdelen_6" isdefault="0" order="6"> <text language="nl">Wiskunde 2</text> </simpleChoice> <simpleChoice id="profielonderdelen_7" isdefault="0" order="7"> <text language="nl">Biologie 1</text> </simpleChoice> <simpleChoice id="profielonderdelen_8" isdefault="0" order="8"> <text language="nl">Biologie 2</text> </simpleChoice> </interaction> <condition operator="=" associatedIdentifier="imanswer_educationStudyhome" itemid="446" outcome="yesno_2"/> </assessmentItem> <assessmentItem identifier="imanswer_educationVWOProfileWork" shortname="Studiehuis profielwerkstuk onderwerp" id="450" itemidentifier="im030000_item_450" basetype="string" rendertype="text" cardinality="single" order="10" focus="0" required="1" labelposition="top" hidden="0"> <title contentCode="content04_02_0964"> <text language="nl">Onderwerp profielwerkstuk:</text> </title> <aliasTitle contentCode="im030000_content_1681"> <text language="nl"/> </aliasTitle> <aliasExplanation contentCode="im030000_content_1682"> <text language="nl"/> </aliasExplanation> <defaultvalue contentCode="im030000_content_1683"> <text language="nl"/> </defaultvalue> <itemformats contentCode="imanswer_educationVWOProfileWork_format"/> <interaction interactionType="stringInteraction" identifier="stringInteraction04_02_0964" maxchoice="1"/> <condition operator="=" associatedIdentifier="imanswer_educationStudyhome" itemid="446" outcome="yesno_2"/> </assessmentItem> <assessmentItem identifier="imanswer_averageExaminationGrade" shortname="Gemiddeld eindexamencijfer" id="451" itemidentifier="im030000_item_451" basetype="string" rendertype="radiolist" cardinality="multiple" order="11" focus="0" required="1" labelposition="top" hidden="0"> <title contentCode="content04_01_0652"> <text language="nl">Wat was je gemiddelde eindexamencijfer op de middelbare school?</text> </title> <aliasTitle contentCode="im030000_content_1684"> <text language="nl"/> </aliasTitle> <aliasExplanation contentCode="im030000_content_1685"> <text language="nl"/> </aliasExplanation> <defaultvalue contentCode="im030000_content_1686"> <text language="nl"/> </defaultvalue> <itemformats contentCode="imanswer_averageExaminationGrade_format"/> <interaction interactionType="choiceInteraction" identifier="eindexamencijferInteraction" maxchoice="1"> <simpleChoice id="eindexamencijfer_1" isdefault="0" order="1"> <text language="nl">Minder dan 6.5</text> </simpleChoice> <simpleChoice id="eindexamencijfer_2" isdefault="0" order="2"> <text language="nl">Tussen 6.5 en 7.5</text> </simpleChoice> <simpleChoice id="eindexamencijfer_3" isdefault="0" order="3"> <text language="nl">Hoger dan 7.5</text> </simpleChoice> </interaction> <condition/> </assessmentItem> </assessmentSection> <assessmentSection id="219" identifier="im030000_section_219" type="set" order="3"> <title contentCode="im030000_content_1655"> <text language="nl">Opleiding algemeen</text> </title> <explanation contentCode="im030000_content_1656"> <text language="nl">Vul hier de opleiding in die je wilt gaan volgen. Wil je je voor meerdere opleidingen van de faculteit Natuurwetenschappen, Wiskunde en Informatica van de UvA aanmelden, vul dan voor iedere opleiding een apart formulier in.</text> </explanation> <assessmentItem identifier="im030000_itembank_studyProgramFNWI" shortname="Studieprogramma FNWI" id="452" itemidentifier="im030000_item_452" basetype="string" rendertype="select" cardinality="multiple" order="2" focus="0" required="1" labelposition="top" hidden="0"> <title contentCode="content04_04_01100FNWI"> <text language="nl">Welke opleiding wil je gaan volgen?</text> </title> <aliasTitle contentCode="im030000_content_1687"> <text language="nl"/> </aliasTitle> <aliasExplanation contentCode="im030000_content_1688"> <text language="nl"/> </aliasExplanation> <defaultvalue contentCode="im030000_content_1689"> <text language="nl"/> </defaultvalue> <itemformats contentCode="im030000_itembank_studyProgramFNWI_format"/> <interaction interactionType="choiceInteraction" identifier="studyProgramFNWIInteraction" maxchoice="1"> <simpleChoice id="studyProgramFNWI_3047" isdefault="0" order="1"> <text language="nl">Aardwetenschappen</text> </simpleChoice> <simpleChoice id="studyProgramFNWI_3048" isdefault="0" order="3"> <text language="nl">Biologie</text> </simpleChoice> <simpleChoice id="studyProgramFNWI_3049" isdefault="0" order="2"> <text language="nl">Bio-exact</text> </simpleChoice> <simpleChoice id="studyProgramFNWI_3050" isdefault="0" order="5"> <text language="nl">Informatica</text> </simpleChoice> <simpleChoice id="studyProgramFNWI_3051" isdefault="0" order="6"> <text language="nl">Informatiekunde</text> </simpleChoice> <simpleChoice id="studyProgramFNWI_3052" isdefault="0" order="7"> <text language="nl">Kunstmatige intelligentie</text> </simpleChoice> <simpleChoice id="studyProgramFNWI_3053" isdefault="0" order="8"> <text language="nl">Natuur- en sterrenkunde</text> </simpleChoice> <simpleChoice id="studyProgramFNWI_3054" isdefault="0" order="9"> <text language="nl">Natuurwetenschappen</text> </simpleChoice> <simpleChoice id="studyProgramFNWI_3055" isdefault="0" order="11"> <text language="nl">Scheikunde</text> </simpleChoice> <simpleChoice id="studyProgramFNWI_3057" isdefault="0" order="12"> <text language="nl">Wiskunde</text> </simpleChoice> <simpleChoice id="studyProgramFNWI_3058" isdefault="0" order="4"> <text language="nl">Bio-medische wetenschappen</text> </simpleChoice> <simpleChoice id="studyProgramFNWI_3059" isdefault="0" order="10"> <text language="nl">Psychobiologie</text> </simpleChoice> </interaction> <condition/> </assessmentItem> </assessmentSection> </assessmentSection> </assessment> </assessments> Thanx for any help you can give. Eric van der Steen

RE: ClassCastException: TinyElementImpl - Added by Anonymous about 16 years ago

Legacy ID: #4989049 Legacy Poster: Michael Kay (mhkay)

The JAXP XPath API is designed to work with multiple data models, and Saxon's implementation works with DOM, XOM, JDOM, and DOM4J as well as the native Saxon NodeInfo model. When you use an XPath expression that selects nodes from a source document, the basic rule is that the kind of node you get back is the same as the kind of node you supplied in the first place. So if you want DOM nodes out, you need to put DOM nodes in, which you can do by supplying a DOMSource as the Source object. You need to be aware that DOM processing with Saxon is a lot slower than using the native NodeInfo model, so depending on your application, you may be better off casting the result to net.sf.saxon.om.NodeInfo and using the NodeInfo methods to manipulate the result.

RE: ClassCastException: TinyElementImpl - Added by Anonymous about 16 years ago

Legacy ID: #4989119 Legacy Poster: EvdS (esteen)

Dear Michael, Thanks for your fast reply. I actually got it working by putting in a DOM document: StringReader stringIn = new StringReader(xml); InputSource inputSource = new InputSource(stringIn); DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(true); Document doc = dfactory.newDocumentBuilder().parse(inputSource); XPath xpath = XPathFactory.newInstance().newXPath(); Node n = (Node) xpath.evaluate(xpathExpressionStr, doc, XPathConstants.NODE); What I actually want to do is to get out a xml fragment in String representation based on the xpath expression, but I need to remain w3c compliant. For now, it is working, but indeed not with good performance. Thanks again for your suggestion.

RE: ClassCastException: TinyElementImpl - Added by Anonymous about 16 years ago

Legacy ID: #4989161 Legacy Poster: Michael Kay (mhkay)

>but I need to remain w3c compliant JAXP interfaces are not actually defined by W3C. I think your most performant and portable solution is probably to do this in XSLT; use the JAXP transform interfaces to run the transformation <xsl:template match="/"> <xsl:copy-of select="//assessmentSection[@id='218']"/> </xsl:template> Alternatively you could use the XQJ interfaces, treating your path expression as an XQuery. This path expression can actually be executed by Saxon-SA in streaming mode, so you don't need to build the whole input tree in memory.

    (1-4/4)

    Please register to reply