Bug 47468 - enable support to manage xs:any nodes with XMLBeans
Summary: enable support to manage xs:any nodes with XMLBeans
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.5-dev
Hardware: PC Mac OS X 10.4
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-02 07:50 UTC by Roberto Manicardi
Modified: 2009-07-07 22:59 UTC (History)
0 users



Attachments
XLSX file with a single xml cell custom xml mapping (9.67 KB, application/octet-stream)
2009-07-02 07:50 UTC, Roberto Manicardi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Roberto Manicardi 2009-07-02 07:50:29 UTC
Created attachment 23922 [details]
XLSX file with a single xml cell custom xml mapping

to use the Custom XML Mapping an XML Schema is saved in the .xlsx  
file. I would like to access to this schema using the ooxml-schema API  
but I can't find any useful accessor method.


An example of the xml where the schema is saved is the following:


<MapInfo>
  <Schema ID="Schema1" >
   <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="">
   ...
  </xsd:schema>
  </Schema>
...
</MapInfo>


The Schema element is of complex type CT_Schema

<complexType name="CT_Schema">
   <sequence>
    <any/>
   </sequence>
   <attribute name="ID" type="xsd:string" use="required"/>
   <attribute name="SchemaRef" type="xsd:string" use="optional"/>
   <attribute name="Namespace" type="xsd:string" use="optional"/>
</complexType>

so to access to the schema I need to navigate the <any/> part of the  
xml.

The complex type CT_Schema is mapped to the class CTSchema which has  
only the getID(),getNamsepace() and getSchemaRef() methods and there  
is no way to access to the <any/> part of the xml.

According to this (http://xmlbeans.apache.org/docs/2.0.0/guide/conHandlingAny.html 
) there should be also a getArrayofany() method. I think there must be  
an option to tell XMLBeans to generate the accessor method also for  
the <any/> node.
Have you any clue on how to enable this?
Comment 1 Yegor Kozlov 2009-07-07 22:59:05 UTC
Roberto,

There are two ways how you can access XML that does not have a getXXX() accessor:

 (1) Grab the DOM node and navigate using the DOM API:
   Node node = xmlobject.getDomNode();
   NodeList ch = node.getChildNodes();
   ...etc.

 (2) Use built-in support for XPath.  The XmlBeans API uses a dialect of XPath, please consult http://xmlbeans.apache.org/ for further details. 
Below is a sample code that reads xsd from the attached file:

        XSSFWorkbook wb = new XSSFWorkbook("CustomXMLMappings.xlsx");
        List<POIXMLDocumentPart> rel = wb.getRelations();
        for(POIXMLDocumentPart p : rel){
            if("http://schemas.openxmlformats.org/officeDocument/2006/relationships/xmlMaps".
                    equals(p.getPackageRelationship().getRelationshipType())){


                InputStream is = p.getPackagePart().getInputStream();
                CTSchema ct = CTSchema.Factory.parse(is);

                //select XML tree for the  schema
                String query =
                    "declare namespace w='http://schemas.openxmlformats.org/spreadsheetml/2006/main';" +
                    "$this/w:MapInfo/w:Schema";

                XmlObject[] o = ct.selectPath(query);
                for (XmlObject xsd : o){
                    XmlCursor cur = xsd.newCursor();
                    cur.selectPath("./*/*");
                    while (cur.toNextSelection()) {
                        XmlObject ch = cur.getObject();
                        System.out.println(ch);
                    }
                }
            }
        }

Regards,
Yegor