Bhasker Reddy

Ranch Hand
+ Follow
since Jun 13, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bhasker Reddy

I get xml files with these special characters. My parser is failing for these characters. Is there anyway i can tell my parser to ignore these
<NAME><![CDATA[Unlimited N&W]]></NAME>.
When my parser tries to retrive this values(Unlimited N&W) it fails.
It is not the issue. Actually when I am trying to parse.
Cr�ditos, Ajustes y Otros Cargos.
I can successfully parse and write it out to a file on windows machine.
But on unix, when I parse and print it out to a file, it gets converted to a Cr?ditos, Ajustes y Otros Cargos.
It is generating a question mark on Unix for special characters. Do you guys know the reason why it is happening.
I am trying to parse a xml file that contains the following string.
Cr�ditos Ajustes & Otros Cargos.
but the parser doesn't recognize this characters. I am using the correct encoding 'iso-8859-1'. It gives me this error

loadDOM threw org.xml.sax.SAXParseException: Illegal character or entity reference syntax.

org.xml.sax.SAXParseException: Illegal character or entity reference syntax.

at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)

at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3170)

at org.apache.crimson.parser.Parser2.maybeReferenceInContent(Parser2.java:2420)

at org.apache.crimson.parser.Parser2.content(Parser2.java:1833)

at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)

at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)

at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)

at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)

at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)

at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)

at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)

at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:151)

at com.cingular.olam.tlgpreprocessor.spanish.spanishParser.parse(spanishParser.java:89)java.lang.NullPointerException

at com.cingular.olam.tlgpreprocessor.spanish.spanishParser.parse(spanishParser.java:105)

at com.cingular.olam.tlgpreprocessor.spanish.spanishBill.create(spanishBill.java:33)

at com.cingular.olam.tlgpreprocessor.spanish.spanishBill.create(spanishBill.java:33)

at com.cingular.olam.tlgpreprocessor.spanish.spanishTest.main(spanishTest.java:35)



at com.cingular.olam.tlgpreprocessor.spanish.spanishTest.main(spanishTest.java:35)

Exception in thread "main"
Can you guys help me out here.
I am trying to execute a jar file
by using this command
java -jar myapp.jar -r
It is giving me this error.
I created myapp.jar using JBUILDER java archive builder tool by selecting
all the java classes in my app and providing main class.
Do you have any idea why this is happening
Exception in thread "main" java.util.zip.ZipException: No such file or directory
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:112)
at java.util.jar.JarFile.<init>(JarFile.java:117)
at java.util.jar.JarFile.<init>(JarFile.java:55)
19 years ago
I am using DOM parser. But I am trying to write some methods to extract values.
package nortel.xml.datatypes;

import java.io.File;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
import org.w3c.dom.*;
import java.util.*;

import org.xml.sax.*;
//import org.jdom.input.*;
import org.apache.xerces.parsers.DOMParser;
import java.io.*;
import java.util.logging.FileHandler;
import javax.xml.parsers.*;





/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class ParserImp {
public ParserImp() {
}


// Methods
public Node parse(File fileName) {
try{
/*
Document doc = null ;
InputStream ins = new FileInputStream( f );
InputStreamReader isr = new InputStreamReader( ins, "UTF-8" );
LineNumberReader lnr = new LineNumberReader( isr );
InputSource isrc = new InputSource( lnr );
try {
DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
fac.setValidating( false ); // default is false
fac.setIgnoringComments( true );
fac.setIgnoringElementContentWhitespace( true );
DocumentBuilder builder = fac.newDocumentBuilder();
// doc = builder.parse( f );
doc = builder.parse( isrc );
*/

InputStream ins = new FileInputStream( fileName );
InputStreamReader isr = new InputStreamReader( ins, "UTF-8" );
LineNumberReader lnr = new LineNumberReader( isr );
InputSource isrc = new InputSource( lnr );
DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
fac.setValidating(false);
fac.setIgnoringComments(true);
fac.setIgnoringElementContentWhitespace( true );
DocumentBuilder builder = fac.newDocumentBuilder();
Document doc = builder.parse(isrc);
Node node = doc.getFirstChild();
// Node node = null;
// Node node = doc.getParentNode();

System.out.println("node type" + node.getNodeType());
System.exit(-1);
System.out.println("$$$$$$$$$$$$$$$NODE.NODENAME:::::::" + fileName);
return node;


//* To read from string
/* StringReader stringreader = new StringReader(fileName.toString());
InputSource stringInputSource = new InputSource(stringreader);

DOMParser parser = new DOMParser();
parser.parse(stringInputSource);
Document document = parser.getDocument();
Node node = document.getParentNode();
return node;*/

}
catch (Exception e) {
System.err.println("XML Parser Exception: " + e.getMessage());
e.printStackTrace(System.err);
}

return null;
}
public static Node[] getChildren(Node node) {
System.out.println("Node:getNodeNAme::::" + node.getNodeName());
NodeList nodeList = node.getParentNode().getChildNodes();
Node[] nodeArray = new Node[nodeList.getLength()];
for (int idx=0; idx<nodeList.getLength(); idx++){
nodeArray[idx] = nodeList.item(idx);
}
return nodeArray;
}
public static Node[] getChildByName(Node node, String name) {
Node[] nodeArray = getChildren(node);
ArrayList arrList = new ArrayList();
for (int idx=0; idx<nodeArray.length; idx++){
if (nodeArray[idx].getParentNode().getNodeName().equals(name)){
arrList.add(nodeArray[idx]);
}
}
Node[] nodeArrayRet = new Node[arrList.size()];
ListIterator itr = arrList.listIterator();
int idx=0;
while (itr.hasNext()){
nodeArrayRet[idx] = (Node)itr.next();
idx++;
}

return nodeArrayRet;
}
public static Node getFirstChildByName(Node node, String name) {
Node[] nodeArray = getChildren(node);
for (int idx=0; idx<nodeArray.length; idx++){
if (nodeArray[idx].getParentNode().getNodeName().equals(name))
return nodeArray[idx];
}

return null;
}
public static String[] getNodeValueByName(Node node, String name) { return null;}

public static String getFirstNodeValueByName(Node node, String name) {
Node[] nodeArray = getChildren(node);
for (int idx=0; idx<nodeArray.length; idx++){
if (nodeArray[idx].getParentNode().getNodeName().equals(name))
return nodeArray[idx].getParentNode().getNodeValue();
}
return null;
}

public Attr[] getAttributes(Node node) { return null;}
public String getAttributesByName(Node node, String name) { return null;}
public Node[] getNodeDrilled(Node node, String[] path) { return null;}
public Node getFirstNodeDrilled(Node _node, String[] _path) { return null;}
public void fillObject(Node node, String[] path, Object objToFill) { }


}

It's crazy. I cannot understand it. I tried to extract node values from xml file. First by using parse method, get the Main node(Document node) and
then pass that node to a datatype class, that inturn calls the methods in these classes to get values.
Can you guys help me out.
iS there code examples for implementing DOM parser.
I need implementation for these methods to extract values from XML files using DOM parser
// Methods
public Node parse(File fileName) { return null;}
public Node[] getChildren(Node node) { return null;}
public Node[] getChildByName(Node node, String name) { return null;}
public Node getFirstChildByName(Node node, String name) { return null;}
public String[] getNodeValueByName(Node node, String name) { return null;}
public String getFirstNodeValueByName(Node node, String name) { return null;}
public Attr[] getAttributes(Node node) { return null;}
public String getAttributesByName(Node node, String name) { return null;}
public Node[] getNodeDrilled(Node node, String[] path) { return null;}
public Node getFirstNodeDrilled(Node _node, String[] _path) { return null;}
public void fillObject(Node node, String[] path, Object objToFill) { }
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(billFile);
Element root = doc.getRootElement();

I am trying to parse an xml file using JDOM. I am using above lines to create the document from billFile which is a File object. At this point,
doc is in memory. Does it means it holds entire document in memory or it only holds some information, pulls it as and when required.
please clarify
My parse method only takes a fileName and the parser. How do I convert inputstreamREader into a File?
How do you convert a inputstreamReader to a file.
I had a file that has unicode special characters.
File theFile = new File(fileName);
I need to parse this file(xml) and pass ISO-8859-1.

To do this. I am converting it into
InputStream ins = new FileInputStream( theFile );
InputStreamReader isr = new InputStreamReader( ins, "UTF-8" );

I want to convert it back to a File object. How do I do this.
19 years ago
I am trying to parse a small xml file using SAX parser.
I am using the following code
package com.nortel.nimo.logic;
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.helpers.DefaultHandler;
import org.apache.xerces.parsers.SAXParser;



public class OutputGenerator extends DefaultHandler{
private File billFile;
private PrintWriter out;

public static void main (String args[])throws Exception{
OutputGenerator outGen = new OutputGenerator(new File("C:/nortelsax/test/acct.xml"), new PrintWriter(new BufferedWriter(new FileWriter("C:/nortelsax/test/output.xml"))));
//System.setProperty(org.xml.sax.helpers.XMLReaderFactory, com.nortel.nimo.logic.OutputGenerator);

}

public OutputGenerator(File _billFile, PrintWriter _out) {
this.billFile = _billFile;
this.out = _out;
// OutputGenerator handler = new OutputGenerator();
createPreprocessedOutput(this.billFile, this.out);
}

public OutputGenerator(){

}

public static synchronized String createPreprocessedOutput(File billFile, PrintWriter out) {

try {
XMLReader xr = XMLReaderFactory.createXMLReader();
OutputGenerator handler = new OutputGenerator();
xr.setContentHandler(handler);
xr.setErrorHandler(handler);

FileReader r = new FileReader(billFile);
xr.parse(new InputSource(r));

System.out.println(billFile + " is well-formed.");
}
catch (SAXException e) {
System.out.println(billFile + " is not well-formed." + e.getMessage());
}
catch (IOException e) {
System.out.println("Due to an IOException, the parser could not check " + billFile);
}

return "success";
}

public void startDocument ()
{
System.out.println("Start document");
}

public void endDocument ()
{
System.out.println("End document");
}

public void startElement (String uri, String name,
String qName, Attributes atts)
{
if ("".equals (uri))
System.out.println("Start element: " + qName);
else
System.out.println("Start element: {" + uri + "}" + name);
}

public void endElement (String uri, String name, String qName)
{
if ("".equals (uri))
System.out.println("End element: " + qName);
else
System.out.println("End element: {" + uri + "}" + name);
}




}
I am getting an error, it says system property org.xml.sax.driver not specified. Is driver something that we need to include, wHAT IS DRIVER
HOW DO WE INCLUDE IT??
Can anyone explain it to me.
My big file will have the following structure
xmlfile1
xmlfile2
xmlfile3
xmlfile4.
It will have xmlfiles one after another. As you said the entire file will be loaded into memory. That could be a problem in my case, because the
files are in the order of 4 to 7 gigs. I cannot afford to load them in memory. Do you think memory mapping is helpful in this case.
Thanks
19 years ago
How do i use nio package to split a file. I need to split a large file of the order gigs which inturn contain multiple xml files. I was told by someone to use nio package and memory mapping interface. But I am not sure
what memory mapping interface is or how to use nio package.
Does anyone of you have an idea. Basically what I need to do is split a large file that contains multiple xml files that start <!xml version. I currently use regular io package, it's very slow. If I use nio, is it very faster. Please let me know
Thanks
19 years ago
Do you guys know any good books for SAX PARSER or any good resouces on internet. Please let me know. I have to start working on converting a Parsing and converting xml file to a preprocessed text file.
--Thanks for your help
Do you guys know any good books for SAX PARSER or any good resouces on internet. Please let me know. I have to start working on converting a Parsing and converting xml file to a preprocessed text file.
--Thanks for your help
These spanish characters are causing my xml parser to crash
<TEXT>�Prefieres tus facturas en espa�ol? Llama al 1-866-xxxxx</TEXT>
<TEXT>para m�s detalles.</TEXT>.
giving me grief
org.xml.sax.SAXParseException: Character conversion error: "Unconvertible UTF-8 character beginning with 0xbf" (line number may be too low).
at org.apache.crimson.parser.InputEntity.fatal(InputEntity.java:1100)
at org.apache.crimson.parser.InputEntity.fillbuf(InputEntity.java:1072)
at org.apache.crimson.parser.InputEntity.isXmlDeclOrTextDeclPrefix(InputEntity.java:914)
at org.apache.crimson.parser.Parser2.maybeXmlDecl(Parser2.java:1048)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:520)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:318)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:151)
at edocs.xcc.parser.implementation.ParserImp.parse(ParserImp.java:52)
at com.nortel.b2b.dps.parser.xmlparser.planCreator.create(planCreator.java:31)
at com.nortel.b2b.dps.parser.xmlparser.ObjectAgent.run(ObjectAgent.java:60)

Is there a way i can convert these special characters to ? or something like
that