Uploaded image for project: 'XMLBeans'
  1. XMLBeans
  2. XMLBEANS-161

Unable to cast from cursor.getObject to type generated from schema.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • Version 2 Beta 1
    • None
    • Cursor
    • None

    Description

      When retrieving XML using cursor.getObject, it appears not possible to cast the returned XML to a specific schema type even when the XML conforms to the schema. The following snippet attempts to retrieve elements using XPath, use a cursor to reach a returned element's parent, then cast the parent XML to a schema type. But the cast fails.

      Code attached.

      private String m_namespaceUri = "http://xmlbeans.apache.org/samples/any";

      String namespaceDecl = "declare namespace any='" + m_namespaceUri
      + "'; ";
      XmlObject[] someElements = rootDoc.selectPath(namespaceDecl
      + "$this//any:stringelement");

      for (int i = 0; i < someElements.length; i++)
      {
      XmlCursor editCursor = someElements[i].newCursor();
      editCursor.toParent();
      ListOfStrings stringList = null;
      try

      { // Shouldn't this cast work? // stringList = (ListOfStrings) editCursor.getObject(); System.out.println(stringList); }

      catch (ClassCastException cce)

      { continue; }

      }

      Attachments

        1. TestCode.zip
          20 kB
          Steve Traut

        Activity

          People

            cezar Cezar Cristian Andrei
            straut Steve Traut
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: