Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Is XOM an appropriate tool for this task?

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Jean Pierre Malrieu <jp.malrieu AT free.fr>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Is XOM an appropriate tool for this task?
  • Date: Mon, 11 Jun 2007 14:31:56 +0200

Hi,

Again, keep in mind I am a xml beginner.

I have to parse and retrieve the information from xml documents which are an awful mixture of "real" xml and text.
Until now I was using xmlBeans to do it. But as the schema of the xml documents redefines the whole XHTML, and introduces many intermediate types, xmlBeams produces 9 MB of jars! There are several versions of the schema, so the xmlBeans approach has to be abandonned (although it worked): I can't add this amount of jars to my app every-time a new schema comes out.

I need to walk the xml with some sort of cursor (like the xmlCursor in xmlBeans). I don't think there is another way of doing given the amount of text or xhtml spread all around, and at any level... But I may be wrong.

To give you an idea of what I was doing with xmlbeans:

Basically, I am building the xhtmlStr string, except when dealing with really structured data, that I map to my own data structures (not shown here).

private void processToken(XmlCursor curs, AssessmentItemType aType) throws QTIException {
switch (curs.currentTokenType().intValue()) {
case TokenType.INT_START:
String elementName =
curs.getName().getLocalPart();

// deal with really structured xml first

if ( isStructuredData(elementName) )
ProcessStructuredData(elementName) );

// if the content is a mixture of text and xhtml keep a stack of xhtml tags

else {
xhtmlStr = xhtmlStr.concat("<" + elementName +
">");
poppedNames.addObject(elementName);

}
break;

// append text to a string

case TokenType.INT_TEXT:

xhtmlStr =
xhtmlStr.concat(curs.getTextValue());
break;

// closes the xhtml tag and remove the tag
from the stack

case TokenType.INT_END:
String lsStr =
(String)poppedNames.lastObject();
if ( !( "null".equals(lsStr) ||
"itemBody".equals(lsStr) ) )
xhtmlStr = xhtmlStr.concat( "</" +
poppedNames.lastObject() + ">");
poppedNames.removeLastObject();
break;


// deal with attributes

case TokenType.INT_ATTR:
if ( curs.getName() != null ) {
xhtmlStr =
xhtmlStr.substring(0,xhtmlStr.length() -1);

// Modify some attributes before
copying them

if
(curs.getName().getLocalPart().equals("src") )
xhtmlStr = xhtmlStr.concat(" src" + "=\"/QTI/" + curs.getTextValue() + "\">");

// or just copy them as they are


else
xhtmlStr = xhtmlStr.concat(" " + curs.getName().getLocalPart() + "=\"" + curs.getTextValue() + "\">");
}
break;
}
}


What tool would you recommend to do this kind of xml walking? Is there something equivalent in XOM? In another API? Is there a much better way of doing what I want? I just figured this method out of my inexistent knowledge of xml... What would you recommend?

Thanks.

JPM










Archive powered by MHonArc 2.6.24.

Top of Page