aspose file tools*
The moose likes XML and Related Technologies and the fly likes An exception in java-XML --kindly clarify-urgent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "An exception in java-XML --kindly clarify-urgent" Watch "An exception in java-XML --kindly clarify-urgent" New topic
Author

An exception in java-XML --kindly clarify-urgent

aarthy kasi
Greenhorn

Joined: Jun 18, 2001
Posts: 2
Hi,
I have built a project in JBuilder. I am using XML4j.jar for parsing xml. As soon as I receive a xml as input, I get the following exception. But there is no error in parsing the xml. Everything works fine. I don't see any "com.ibm.xml.internal.msg.Message" class in the jar file.
Can't find resource for base name com.ibm.xml.internal.msg.Message, locale en_US
at com.ibm.xml.framework.XMLParser.parse(XMLParser.java)
at com.ibm.xml.parsers.NonValidatingDOMParser.parse(NonValidatingDOMParser.java)
Can anyone help me explain why i get this exception. It is urgent.
Thanks,
Aarthy
madhava g
Greenhorn

Joined: Jun 19, 2001
Posts: 1
Hi,
Unless you post your XML file,i don't think so one would be able to help you much. By the way you could use xerces(originally XML4J of IBM, IBM had donated this to APACHE.) from apache. It nearly confines to the XML standards.
thanks,
/GM.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Pardon me for raining the parade.
Your name "madhava g" does not comply with the JavaRanch naming policy. Please spare a moment and re-register with a name that meets the requirements. We will take care of deleting your current login.
Please note that without a name that complies with the Javaranch naming policy, you will not qualify for any giveaways. So I guess changing it is worth the trouble
Thanks!
Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
aarthy kasi
Greenhorn

Joined: Jun 18, 2001
Posts: 2
Hi,
I am writing the code where I get the exception. The exception occurs in makeDatGroup(). I have given a "e.printStacktrace" in the catch block of makeDataGroup(). To be more exact I think the error comes when we execute the "parser.parse(insource);" statement of the above said method.
import java.io.*;
import com.ibm.xml.parser.*;
import org.w3c.dom.*;
import org.xml.sax.InputSource; // Required by DOM Parser
import com.ibm.xml.parsers.DOMParser;
import com.ibm.xml.parsers.NonValidatingDOMParser; // XML DOM Parser
/** class XMLDataGroupFactory
*
* @see makeDataGroup(String buffer)
* @see putLine(String line)
* @see makeDataGroup()
* @since JDK 1.3
*/
public class XMLDataGroupFactory {
public XMLDataGroupFactory() {
buffer=new StringBuffer(200);
}
/** Add some information to the current buffer */
public boolean putLine(String line) {
// If we don't know the doc name yet, establish the name
if (docName==null && line!=null && line.length()>2) {
docName=line.substring(1,line.length()-1);
endOfDocName="</"+docName+">";
}
buffer.append(line);
// Use a newline so we can see breaks in the source data for multi-line fields
// and also so we can return the line number for errors
buffer.append("\r\n");
/** Checks if this is the end of the document for an XML block and
if so it returns true. */
String trimmedline = line.trim();
return ( trimmedline.equals("</") | | trimmedline.equals(endOfDocName) );
}
/** Erase the current buffer and start over. Clears the last error. */
public void reset() {
buffer.setLength(0);
status=null;
docName=null;
endOfDocName=null;
}
/** Set the buffer directly, then parse the XML document in the buffer, and generate either
a DataGroup or an exception.
*/
public DataGroup makeDataGroup(String buffer) throws Exception {
reset();
putLine(buffer);
return makeDataGroup();
}

/** Parse the XML document in the buffer, and generate either a DataGroup or an exception. */
public DataGroup makeDataGroup() throws Exception {
// Copy off the data and clear the buffer we're in a clean state if we get an exception
String xmlData=new String(buffer);
reset();
// New IBM XML Parser from here ....
DOMParser parser = new DOMParser();
StringReader xmlSR = new StringReader(xmlData);
try {
InputSource insource = new InputSource(xmlSR); // Set input source to the StringReader
parser.parse(insource); // Parse it
}
catch (Exception e) {
e.printStackTrace();
}
Document doc = null;
doc = parser.getDocument(); // Results are a document
// .... to here New IBM XML Parser
xmlSR.close(); // Note that this could throw an IOException
if (doc==null | | doc.getDocumentElement()==null) {
String errorInfo;
if (status==null)
errorInfo="";
else
errorInfo=" "+status.getValue("message");
throw new Exception("Invalid XML document");
}
return parseNode(doc.getDocumentElement());
}
// Parse a node, and produce a dataGroup to represent that node
// old private static DataGroup parseNode(Node parentNode) {
private static DataGroup parseNode(Node node) {
// New IBM XML Parser here ....
DataGroup datagroup = new DataGroup(node.getNodeName());
NodeList children = node.getChildNodes();
if (children != null) {
int len = children.getLength();
for (int i = 0; i < len; i++) { // loop thru all children
if ( children.item(i).getNodeType() == Node.ELEMENT_NODE ) {
if (hasElementChildren(children.item(i))==true) { // if has children
datagroup.addDataGroup(parseNode(children.item(i))); // parse the child into a datagroup
}
else {
if ( children.item(i).hasChildNodes() == true ) { // Make sure there is data for this tag
datagroup.addValue(children.item(i).getNodeName(),children.item(i).getLastChild().getNodeValue());
}
// The above is with the assumption that the last child is a text node.
// If dante ever starts accepting other node types ( like comments ). This will have to be
// restructered
}
}
}
}
return datagroup;
// .... to here New IBM XML Parser
}
// Any node that has text will return true for hasChildren. This method tells you
// whether a node has any Element children.
private static boolean hasElementChildren(Node node) {
boolean hasChildren=false;
for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling()) {
int type=n.getNodeType();
if (type==node.ELEMENT_NODE) { // Skip the text elements
hasChildren=true;
break;
}
}
return hasChildren;
}

public DataGroup makeDataGroup(BufferedReader in) throws Exception {
String line;
reset();
boolean beginTagFound = false;
String beginTag = null;
while (true) {
line = null;
line=in.readLine();
if (line == null)
if (beginTagFound == false)
return null;
else
break;
if( !beginTagFound ) {
int index = line.indexOf('<');
if( index != -1 ) {
int endIndex = line.indexOf('>',index);
if( endIndex != -1 && endIndex>index+1 ) {
beginTag = line.substring(index+1, endIndex);
beginTagFound = true;
}
}
}
putLine(line);
//if (line.startsWith("</")) break;
if (line.equals("</") | | line.indexOf("</"+beginTag+">") != -1)
break;
}
return makeDataGroup();
}
/** Returns information about the last parsing error.
Returns null if there is no last error to report.
Note that the reset() method clears the last error. */
public DataGroup getLastError() {
return status;
}
private void setLastError(DataGroup err) {
status=err;
}
// Inner class for error handling
class ErrorHandler implements ErrorListener {
public ErrorHandler(XMLDataGroupFactory parent) {
this.parent=parent;
}
public int error(String fileName, int lineNo, int charOffset, Object key, String msg) {
DataGroup err=new DataGroup("ParserError");
//Don't return line-- it always will be one because of the way we concatenate
//everything into a single line
//err.setValue("line",lineNo);
err.setValue("character_offset",charOffset);
err.setValue("message",msg);
parent.setLastError(err);
return 1;
}
private XMLDataGroupFactory parent;
} // ErrorHandler inner class
private String endOfDocName=null;
private String docName=null;
private DataGroup status;
private StringBuffer buffer;
}

Thanks,
Aarthy
 
 
subject: An exception in java-XML --kindly clarify-urgent