This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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

aarthy kasi

Joined: Jun 18, 2001
Posts: 2
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 "" class in the jar file.
Can't find resource for base name, locale en_US
Can anyone help me explain why i get this exception. It is urgent.
madhava g

Joined: Jun 19, 2001
Posts: 1
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.
Ajith Kallambella

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

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

Joined: Jun 18, 2001
Posts: 2
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 org.w3c.dom.*;
import org.xml.sax.InputSource; // Required by DOM Parser
import; // 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) {
// 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
/** 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() {
/** 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 {
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);
// 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) {
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=" "+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
// 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
return hasChildren;

public DataGroup makeDataGroup(BufferedReader in) throws Exception {
String line;
boolean beginTagFound = false;
String beginTag = null;
while (true) {
line = null;
if (line == null)
if (beginTagFound == false)
return null;
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;
//if (line.startsWith("</")) break;
if (line.equals("</") | | line.indexOf("</"+beginTag+">") != -1)
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) {
// Inner class for error handling
class ErrorHandler implements ErrorListener {
public ErrorHandler(XMLDataGroupFactory 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
return 1;
private XMLDataGroupFactory parent;
} // ErrorHandler inner class
private String endOfDocName=null;
private String docName=null;
private DataGroup status;
private StringBuffer buffer;

Have you checked out Aspose?
subject: An exception in java-XML --kindly clarify-urgent
jQuery in Action, 3rd edition