SAXParseException from parser.parse()

Hi,
I am using xml on http sample code with xerces-123 and I get I get
"SAXParseException: The root element is required in a well-formed document."
on the parser.parse(...) line. Yes, the XML is well-formed. I also try to
use a well-formated xml file, but that exception is still there.
import org.w3c.dom.*;
import org.apache.xerces.*;
import org.apache.xerces.dom.*;
import org.apache.xerces.parsers.*;
import org.apache.xml.serialize.*;
import org.xml.sax.*;
import java.net.*;
import java.io.*;
class XmlBridge {
private String sURI;
public XmlBridge(String serverURI) {
sURI = serverURI;
public Document sendRequest(Document doc) {
Document docOut = null;
try {
URL url = new URL("http://" + sURI);
HttpURLConnection conn =
(HttpURLConnection)
url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream out =
conn.getOutputStream();
XMLSerializer ser =
new XMLSerializer(out,
new OutputFormat("xml",
"UTF-8", false));
ser.serialize(doc);
out.close();
DOMParser parser = new DOMParser();
parser.parse(new
InputSource(conn.getInputStream()));
docOut = parser.getDocument();
} catch (Throwable e) {
e.printStackTrace();
return docOut;
public static void main(String[] args) {
try {  // Build up an XML Document
Document docIn = new DocumentImpl();
Element e =
docIn.createElement("Order");
e.appendChild(docIn.createElement(
"Type"));
e.appendChild(docIn.createElement(
"Amount"));
docIn.appendChild(e);
// Send it to the Servlet
XmlBridge a =
new XmlBridge(args[0]);
Document docOut =
a.sendRequest(docIn);
// Debug - write the sent
//Document to stdout
XMLSerializer ser =
new XMLSerializer(System.out,
null);
ser.serialize(docOut);
} catch (Throwable e) {
e.printStackTrace();
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xerces.*;
import org.apache.xerces.dom.*;
import org.apache.xerces.parsers.*;
import org.apache.xml.serialize.*;
public abstract class XmlServlet
extends GenericServlet {
protected abstract Document
doRequest(Document req);
public XmlServlet() {}
public void service(ServletRequest
req, ServletResponse res)
throws ServletException {
try {
DOMParser parser =
new DOMParser();
//problem here
parser.parse(new InputSource(
req.getInputStream()));
Document docOut =
doRequest(
parser.getDocument());
XMLSerializer ser =
new XMLSerializer(
res.getOutputStream(),
new OutputFormat("xml",
"UTF-8", false));
ser.serialize(docOut);
res.getOutputStream().close();
} catch (Throwable e) {
e.printStackTrace();
I use VCafe to bebug the xmlservlet. For some reason in line
parser.parse(new InputSource(req.getInputStream())), parse() method is
frozen and stop running. Is anyone has some solution or experience on this
problem. Any help will be appreciated.
DJ

I fix this problem by upgrade to sp8. But why?
"Cameron Purdy" <[email protected]> wrote in message
news:[email protected]...
1. It will freeze if it can't read from the input stream. Read is a
blocking call.
2. It may be in your code since it calls you for each piece. Use
Ctrl-Break to get a thread dump (kill -3 on Unix).
Cameron Purdy
Tangosol, Inc.
http://www.tangosol.com
+1.617.623.5782
WebLogic Consulting Available
"David Jian" <[email protected]> wrote in message
news:[email protected]...
Hi,
I am using xml on http sample code with xerces-123 and I get I get
"SAXParseException: The root element is required in a well-formeddocument."
on the parser.parse(...) line. Yes, the XML is well-formed. I also try
to
use a well-formated xml file, but that exception is still there.
import org.w3c.dom.*;
import org.apache.xerces.*;
import org.apache.xerces.dom.*;
import org.apache.xerces.parsers.*;
import org.apache.xml.serialize.*;
import org.xml.sax.*;
import java.net.*;
import java.io.*;
class XmlBridge {
private String sURI;
public XmlBridge(String serverURI) {
sURI = serverURI;
public Document sendRequest(Document doc) {
Document docOut = null;
try {
URL url = new URL("http://" + sURI);
HttpURLConnection conn =
(HttpURLConnection)
url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream out =
conn.getOutputStream();
XMLSerializer ser =
new XMLSerializer(out,
new OutputFormat("xml",
"UTF-8", false));
ser.serialize(doc);
out.close();
DOMParser parser = new DOMParser();
parser.parse(new
InputSource(conn.getInputStream()));
docOut = parser.getDocument();
} catch (Throwable e) {
e.printStackTrace();
return docOut;
public static void main(String[] args) {
try {  // Build up an XML Document
Document docIn = new DocumentImpl();
Element e =
docIn.createElement("Order");
e.appendChild(docIn.createElement(
"Type"));
e.appendChild(docIn.createElement(
"Amount"));
docIn.appendChild(e);
// Send it to the Servlet
XmlBridge a =
new XmlBridge(args[0]);
Document docOut =
a.sendRequest(docIn);
// Debug - write the sent
//Document to stdout
XMLSerializer ser =
new XMLSerializer(System.out,
null);
ser.serialize(docOut);
} catch (Throwable e) {
e.printStackTrace();
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xerces.*;
import org.apache.xerces.dom.*;
import org.apache.xerces.parsers.*;
import org.apache.xml.serialize.*;
public abstract class XmlServlet
extends GenericServlet {
protected abstract Document
doRequest(Document req);
public XmlServlet() {}
public void service(ServletRequest
req, ServletResponse res)
throws ServletException {
try {
DOMParser parser =
new DOMParser();
//problem here
parser.parse(new InputSource(
req.getInputStream()));
Document docOut =
doRequest(
parser.getDocument());
XMLSerializer ser =
new XMLSerializer(
res.getOutputStream(),
new OutputFormat("xml",
"UTF-8", false));
ser.serialize(docOut);
res.getOutputStream().close();
} catch (Throwable e) {
e.printStackTrace();
I use VCafe to bebug the xmlservlet. For some reason in line
parser.parse(new InputSource(req.getInputStream())), parse() method is
frozen and stop running. Is anyone has some solution or experience onthis
problem. Any help will be appreciated.
DJ

Similar Messages

  • Tagged text from standford parser

    Hello all!
    I am using the nlp(Natural language processing).
    I am using the standford parser.
    My target is to get tagged text from standford parser,
    Example from here:
    http://nlp.stanford.edu:8080/parser/
    like :
    the screen is samsung is good
    output:
    the/DT screen/NN is/VBZ samsung/JJ is/VBZ good/JJ
    my code is:
       LexicalizedParser lp = new LexicalizedParser("C:\\englishPCFG.ser");
        lp.setOptionFlags(new String[]{"-maxLength", "80", "-retainTmpSubcategories"});
        String sent ="sound on samsung galaxy is the best.";
        Tree parse = (Tree) lp.apply(Arrays.asList(sent));
    //  parse.pennPrint();
        System.out.println();
        TreebankLanguagePack tlp = new PennTreebankLanguagePack();
        GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
        GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
        Collection tdl = gs.typedDependenciesCollapsed();
        TreeGraphNode sentence = new TreeGraph(parse).root();the api of this is here:
    http://tides.umiacs.umd.edu/webtrec/stanfordParser/javadoc/
    but I didnt find it.
    thanks for helping

    I am presuming that your question is that you don't know where to get the info from.
    So experiment.
    For example use Tree.pennPrint().
    And tdl is a collection. So iterate through that collection, get each item and print the properties of each

  • How to get a specific tag value from SAX parser

    I am using the SAX method to parse my xml file.
    My Question is how to get the returning characters parsed after calling?
    esp the value of <body> tag?
    Here is my xml file, and i want to get the parsed <body> value after call sax parser.
    <?xml version="1.0" encoding="UTF-8"?>
    <article>
    <content>
    <title>floraaaaa</title>
    <date>2004-03-19</date>
    <body>
    Details of an article, and i want to get the article details
    </body>
    </content>
    </article>

    here is the parser code I am using:
    import java.io.*;
    import org.apache.xerces.parsers.SAXParser;
    import org.xml.sax.Attributes;
    import org.xml.sax.ContentHandler;
    import org.xml.sax.ErrorHandler;
    import org.xml.sax.Locator;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.XMLReader;
    import org.xml.sax.helpers.XMLReaderFactory;
    public class test2 {
         public String m_xmlDetail;
         public void readDetail(String url) {
              System.out.println("Parsing XML File: " + url + "\n\n");
              try {
                   XMLReader parser = new SAXParser();
                   ContentHandler contentHandler = new MyContentHandler();
                   parser.setContentHandler(contentHandler);
                   parser.parse(url);
              } //try ends here
              catch (IOException e) {
                   System.out.println("Error reading URI: " + e.getMessage());
              } //catch ends here
              catch (SAXException e) {
                   System.out.println("Error in parsing: " + e.getMessage());
              } //catch ends here
         } //function
    }//close class
    public class MyContentHandler implements ContentHandler {
         private Locator locator;
         //public String m_bodyDetail=new String();
         public void setDocumentLocator(Locator locator) {
              System.out.println(" * setDocumentLocator() called");
              this.locator = locator;
         public void startDocument() throws SAXException {
              System.out.println("Parsing begins...");
         public void endDocument() throws SAXException {
              System.out.println("...Parsing ends.");
         public void processingInstruction(String target, String data)throws SAXException {
              System.out.println("PI: Target:" + target + " and Data:" + data);
         public void startPrefixMapping(String prefix, String uri) {
              System.out.println("Mapping starts for prefix " + prefix + " mapped to URI " + uri);
         public void endPrefixMapping(String prefix) {
              System.out.println("Mapping ends for prefix " + prefix);
         public void startElement(String namespaceURI, String localName,String rawName, Attributes atts)throws SAXException {
              System.out.print("startElement: " + localName);
              if (!namespaceURI.equals("")) {
                   System.out.println(" in namespace " + namespaceURI + " (" + rawName + ")");
              else {
                   System.out.println(" has no associated namespace");
              for (int i=0; i<atts.getLength(); i++)
                   System.out.println(" Attribute: " + atts.getLocalName(i) +"=" + atts.getValue(i));
         public void endElement(String namespaceURI, String localName, String rawName) throws SAXException {
              System.out.println("endElement: " + localName + "\n");
         public void characters(char[] ch, int start, int end) throws SAXException {
              String s = new String(ch, start, end);
              System.out.println("characters: " + s);
         public void ignorableWhitespace(char[] ch, int start, int end)throws SAXException {
              String s = new String(ch, start, end);
              System.out.println("ignorableWhitespace: [" + s + "]");
         public void skippedEntity(String name) throws SAXException {
              System.out.println("Skipping entity " + name);
    } //close class

  • Exiting from SAX parser on finding specific element/attribute

    Is there a way to return/exit from a SAX parser as soon as I get my search element the first time, without parsing the whole XML file?
    Please let me know.
    Thanks

    Thanks for the information, but what I am exactly looking for is to only return back from SAX parser to the calling program.
    System.exit(0) shuts down the whole application.
    please let me know

  • Why the oracle XML parser "parses" the DTD comments?

    Hi all,
    I always use the header
    <?xml version = '1.0' encoding='ISO-8859-1' ?>
    to be able to use foreign characters in the XML documents.
    The oracle xml parser handles this correctly.
    My problem is, when I write comments inside the DTD, the
    parser reports "Invalid UTF8 encoding".
    Why the parser "parse" the comments? (protected by <!-- and -->)
    How do I say that the DTD encoding is different from UTF, like
    ISO-8859-1?
    Example of a correct DTD and corresponding XML, reporting
    problems, related to the 2nd comment in the DTD specification,
    written with ISO-8859-1 characters.
    The DTD:
    <!-- valid.dtd -->
    <!ELEMENT valid ( B, C ) >
    <!-- valid represents the concept "Identificagco" -->
    <!ELEMENT B (#PCDATA) >
    <!ELEMENT C (#PCDATA) >
    The XML:
    <?xml version = '1.0' encoding='ISO-8859-1' ?>
    <!DOCTYPE valid SYSTEM 'valid.dtd'>
    <valid>
    <B>How are you, Conceigco</B>
    <C>I'm fine, thank you.</C>
    </valid>
    The parser output:
    [jgr@frontera test-dtd]$ java oracle.xml.parser.v2.oraxml -v
    valid.xml
    Error while parsing input sourcevalid.xml(Invalid UTF8 encoding.)
    Thank you for any help.
    Jorge Gustavo Rocha

    I was wrong in saying that the attributes are not added to the element.My main aim is to add a array of elements to the root node.
    Is there a efficient manner in adding the elements , rather than adding them individually with the help of appendChild method.
    Thanks in advance.
    null

  • HTMLEditorKit.Parser.parse() method is not giving a proper HTMLDocument alw

    Hi,
    I am developing util program for HTML filter, for my project. I have find using HTMLDocument we can do that.
    But when I created I found few starnge things.
    HTMLEditorKit.Parser.parse() method is not giving a proper HTMLDocument always. the below application will show the HTML one if you comment the String str ="" ; and uncomment the next line.
    I am wondering why this happens.
    import java.io.StringReader;
    import java.io.StringWriter;
    import javax.swing.text.html.HTMLDocument;
    import javax.swing.text.html.HTMLEditorKit;
    import javax.swing.text.html.HTMLWriter;
    import javax.swing.text.html.parser.ParserDelegator;
    public class HTMLDocExample {
    public static void main(String args[]) throws Exception {
    System.out.println("start the parsing");
    String data = "dsfdssfsdf<A HREF='http://yahoo.com'>HTMLEditorKit.Parser</A><h1>dsfdsf</h1><table border='1' class='test'><tr><td><input type='text'>dfsf</input><select id='id1' name='name1'><option>fff</option><option>aaaaa</option></select><input type='text'/><a href=#></a></td></tr></table>";
    String str ="" ;
    //String str ="<TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE>" ;
    StringReader br = new StringReader(data + str );
    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
    HTMLEditorKit.Parser parser = new ParserDelegator();
    HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0);
    parser.parse(br, callback, true);
    StringWriter writer = new StringWriter();
    HTMLWriter hWriter = new HTMLWriter(writer, htmlDoc);
    hWriter.write();
    String outPut = writer.toString();
    System.out.println(outPut);
    System.exit(0);
    }

    import java.io.StringReader;
    import java.io.StringWriter;
    import javax.swing.text.html.HTMLDocument;
    import javax.swing.text.html.HTMLEditorKit;
    import javax.swing.text.html.HTMLWriter;
    import javax.swing.text.html.parser.ParserDelegator;
    public class HTMLDocExample {
      public static void main(String args[]) throws Exception {
        System.out.println("start the parsing"); 
        String data = "dsfdssfsdf<A HREF='http://yahoo.com'>HTMLEditorKit.Parser</A><h1>dsfdsf</h1><table border='1' class='test'><tr><td><input type='text'>dfsf</input><select id='id1' name='name1'><option>fff</option><option>aaaaa</option></select><input type='text'/><a href=#></a></td></tr></table>";
        //String str ="" ;
        String str ="<TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE>" ;
        StringReader br = new StringReader(data + str );   
        HTMLEditorKit htmlKit = new HTMLEditorKit();
        HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
        HTMLEditorKit.Parser parser = new ParserDelegator();
        HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0);
        parser.parse(br, callback, true);
        StringWriter writer = new StringWriter();
        HTMLWriter hWriter = new HTMLWriter(writer, htmlDoc);
        hWriter.write();
        String outPut = writer.toString();       
        System.out.println(outPut);
        System.exit(0);
    }

  • Problem with com.sun.xml.parser.Parser

    Hi ,
    I am using weblogic 6.01.
    In my ejb class, I am parsing a String to create XmlDocument.
    I created xml registry in weblogic server.
    In my weblogic server's xml registry,
    I have com.sun.xml.parser.DocumentBuilderFactoryImpl as
    DocumentBuilderFactory
    and com.sun.xml.parser.Parser as parser.
    I am using jaxp 1.1 for all my xml related processing. All required jars are
    in the classpath.
    following is my code
    protected Document createDocument ( String a_sXmlDocument )
    try
    ByteArrayInputStream baInputStream = new ByteArrayInputStream
    (a_sXmlDocument.getBytes ());
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance ();
    DocumentBuilder builder = factory.newDocumentBuilder ();
    Document xmlDocument = builder.parse (baInputStream);
    return xmlDocument ;
    catch (
    I get following exception at builder.parse ( baInputStream )
    Can't find bundle for base name com.sun.xml.parser.resources.Messages,
    locale en
    at com.sun.xml.parser.Parser.parseInternal(Parser.java:516)
    at com.sun.xml.parser.Parser.parse(Parser.java:284)
    at
    com.sun.xml.parser.DocumentBuilderImpl.parse(DocumentBuilderImpl.java
    :95)
    at
    weblogic.xml.jaxp.RegistryDocumentBuilder.parse(RegistryDocumentBuild
    er.java:98)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:78)
    at
    com.datamap.arch.datamap.BasicTransportableDelegate.createDocument(Ba
    I would appreciate if anyone could help in this exception.
    Thank you,
    Mahendra

    Hi ,
    I am using weblogic 6.01.
    In my ejb class, I am parsing a String to create XmlDocument.
    I created xml registry in weblogic server.
    In my weblogic server's xml registry,
    I have com.sun.xml.parser.DocumentBuilderFactoryImpl as
    DocumentBuilderFactory
    and com.sun.xml.parser.Parser as parser.
    I am using jaxp 1.1 for all my xml related processing. All required jars are
    in the classpath.
    following is my code
    protected Document createDocument ( String a_sXmlDocument )
    try
    ByteArrayInputStream baInputStream = new ByteArrayInputStream
    (a_sXmlDocument.getBytes ());
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance ();
    DocumentBuilder builder = factory.newDocumentBuilder ();
    Document xmlDocument = builder.parse (baInputStream);
    return xmlDocument ;
    catch (
    I get following exception at builder.parse ( baInputStream )
    Can't find bundle for base name com.sun.xml.parser.resources.Messages,
    locale en
    at com.sun.xml.parser.Parser.parseInternal(Parser.java:516)
    at com.sun.xml.parser.Parser.parse(Parser.java:284)
    at
    com.sun.xml.parser.DocumentBuilderImpl.parse(DocumentBuilderImpl.java
    :95)
    at
    weblogic.xml.jaxp.RegistryDocumentBuilder.parse(RegistryDocumentBuild
    er.java:98)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:78)
    at
    com.datamap.arch.datamap.BasicTransportableDelegate.createDocument(Ba
    I would appreciate if anyone could help in this exception.
    Thank you,
    Mahendra

  • Com.ibm.xml.parser.Parser Not Found

    Hi,
    I am getting error of Package not found i.e com.ibm.xml.parser.Parser
    But i had this package in my libraries and that have been set to project classpath.
    Still i m getting error , i m totally confused , please tell me how to resolve it I m using NetBeans.
    Nitin

    Hi Ben,
    I have no solution (sorry), but I've the same trouble.
    I would appreciate if you can forward me any given solution.
    Thanks in advance,
    François Le Rolland
    "Benjamin Hyatt" <[email protected]> wrote:
    >
    Weblogic server 5.1sp6, Weblogic Commerce Server 3.1.
    Sun Solaris 5.6, jdk 1.2.2
    When starting commerce server(StartCommerce.sh), I get a 'java.lang.ClassNotFoundException: com.ibm.xml.parser.SAXDriver" error message to stdout.
    I'm having a hard time understanding why. Weblogicaux.jar is in the weblogic server classpath. Just for sanity sake, in StartCommerce.sh I echoed the $JDK_HOME variable under #-- Start WebLogic with the above parameters --
    It is indeed being loaded in the classpath. A quick check via the console confirms this as well.
    Any help is appreciated.
    Thanks,
    -Ben

  • ERROR:  parser: parse error at or near "re"

    hi Experts,
    I've an update statement that does - update scene set text = 'You're right' where id = 196 and ref = 10017;
    My sql statement:
    sql = "update scene set text = '"+c_text+"' where id = "+c_id+" and ref = "+c_ref+";";
    My error:
    ERROR: parser: parse error at or near "re"
    Please offer ur suggestions on how should I update a text with a ' symbol in my word - You're. Thanks.
    Dawn.

    hi All,
    I've found the solution. I can add a backlash so that it'll be recognised.
    Eg: You\'re right
    Dawn.

  • How do I create individual xml files from the parsed data output of a xml file?

    I have written a program (DOM Parser) that parses data from a XMl File. I would like to create an individual file with the corresponding name for each set of data parsed from the xml document. If the parsed output is Single, Double, Triple, I would like to create an individual xml file (Single.xml, Double.xml, Triple.xml)with those corresponding names. How do I create the xml files and give each file the name of my parsed data output? Thanks in advance for your help.
    import java.io.IOException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println("Template" + ": " +templateElement.getAttribute("name")+ ".xml");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

    Ive posted the new code but now I'm getting a FileAlreadyExistException error. How do I handle this exception error correctly in my code?
    import java.io.IOException;
    import java.nio.file.FileAlreadyExistsException;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println(templateElement.getAttribute("name")+ ".xml");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      String fileName = templateElement.getAttribute("name") + ".xml";
      Files.createFile(Paths.get(fileName));
      System.out.println("File" + ":" + fileName + ".xml created");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

  • All validation error from saxParser.parse

    I am getting just the 1st error but I want all the errors in the 1st pass itself.
    Attaching the code for reference also.
    ?would really appreciate you suggestion.
    ==code---
    public class EDITExtractSchema {
    static Document document;
    public void validateXMLVOusingXSD(String str)
    try {
    //create a SchemaFactory capable of understanding W3C XML Schemas (WXS)
    SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    //Set the error handler to receive any error during Schema Compilation
    XMLErrorHandler errorHandler = new XMLErrorHandler();
    factory.setErrorHandler(errorHandler);
    //set the resource resolver to customize resource resolution
    //factory.setResourceResolver( new MyLSResourceResolver());
    // load a WXS schema, represented by a Schema instance
    File schemaFile = new File("C:/Temp/project2-CorrVO/XSDs/TaxExtract5498DetailVO.xsd");
    Schema schema = factory.newSchema(new StreamSource(schemaFile));
    SAXParserFactory spf = SAXParserFactory.newInstance();
    //spf.setNamespaceAware(true);
    //spf.setValidating(true);
    spf.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
    //Just set the Schema instance on SAXParserFactory
    spf.setSchema(schema);
    //Obtain the SAXParser instance
    SAXParser saxParser = spf.newSAXParser();
    //parser will parse the XML document but validate it using Schema instance
    //saxParser.parse(new File(str), myHandler);
    saxParser.parse(new File(str),new MyDefaulyHandler());
    }catch(ParserConfigurationException e) {
    System.out.println("ParserConfigurationException-" + e);
    }catch (SAXException e) {
    System.out.println("SAXException-" + e);
    catch (Exception e) {
    System.out.println("Exception-" + e);
    /*// output the errors XML
    XMLWriter writer = null;
    try {
    writer = new XMLWriter(OutputFormat.createPrettyPrint());
    } catch (UnsupportedEncodingException e) {
    System.out.println("validate error" + e);
    e.printStackTrace();
    try {
    writer.write(errorHandler.geterrors());
    } catch (IOException e) {
    System.out.println("validate error" + e);
    e.printStackTrace();
    //implement error handler
    public static class XMLErrorHandler implements ErrorHandler {
    private boolean valid = true;
    public void reset() {
    // Assume document is valid until proven otherwise
    valid = true;
    public boolean isValid() {
    return valid;
    public void warning(SAXParseException exception) throws SAXException{
    System.out.println("Warning: " + exception.getMessage());
    System.out.println(" at line " + exception.getLineNumber()
    + ", column " + exception.getColumnNumber());
    System.out.println(" in entity " + exception.getSystemId());
    valid = true;
    public void error(SAXParseException exception) throws SAXException{
    System.out.println("Error: " + exception.getMessage());
    System.out.println(" at line " + exception.getLineNumber()
    + ", column " + exception.getColumnNumber());
    System.out.println(" in entity " + exception.getSystemId());
    valid = true;
    /* // output the errors XML
    XMLWriter writer = null;
    try {
    writer = new XMLWriter(OutputFormat.createPrettyPrint());
    } catch (UnsupportedEncodingException e) {
    System.out.println("validate error" + e);
    e.printStackTrace();
    try {
    writer.write((Object)exception);
    } catch (IOException e) {
    System.out.println("validate error" + e);
    e.printStackTrace();
    public void fatalError(SAXParseException exception) throws SAXException {
    System.out.println("Fatal Error: " + exception.getMessage());
    System.out.println(" at line " + exception.getLineNumber()
    + ", column " + exception.getColumnNumber());
    System.out.println(" in entity " + exception.getSystemId());
    valid = true;
    public static class MyDefaulyHandler extends DefaultHandler {
    private boolean valid = true;
    public void reset() {
    // Assume document is valid until proven otherwise
    valid = true;
    public boolean isValid() {
    return valid;
    public void warning(SAXParseException exception) throws SAXException{
    System.out.println("Warning: " + exception.getMessage());
    System.out.println(" at line " + exception.getLineNumber()
    + ", column " + exception.getColumnNumber());
    System.out.println(" in entity " + exception.getSystemId());
    valid = true;
    public void error(SAXParseException exception) throws SAXException{
    System.out.println("Error: " + exception.getMessage());
    System.out.println(" at line " + exception.getLineNumber()
    + ", column " + exception.getColumnNumber());
    System.out.println(" in entity " + exception.getSystemId());
    valid = true;
    /* // output the errors XML
    XMLWriter writer = null;
    try {
    writer = new XMLWriter(OutputFormat.createPrettyPrint());
    } catch (UnsupportedEncodingException e) {
    System.out.println("validate error" + e);
    e.printStackTrace();
    try {
    writer.write((Object)exception);
    } catch (IOException e) {
    System.out.println("validate error" + e);
    e.printStackTrace();
    public void fatalError(SAXParseException exception) throws SAXException {
    System.out.println("Fatal Error: " + exception.getMessage());
    System.out.println(" at line " + exception.getLineNumber()
    + ", column " + exception.getColumnNumber());
    System.out.println(" in entity " + exception.getSystemId());
    valid = true;
    public static void main(String[] args) {
    EDITExtractSchema schemaClass = new EDITExtractSchema();
    try {
    schemaClass.validateXMLVOusingXSD("C:/Temp/project2-CorrVO/XSDs/TaxExtract5498DetailVO.xml");
    }catch (Exception e) {
    System.out.println("xml file read error Exception-" + e);
    --====
    Regards,
    Tapas

    No really, it will report all the error if you turn on the validation and implement the error hander methods(error()).
    ALSO,
    My XSD had "<xs:sequence>" which was causing the problem.
    We had to change it to "<xs:all>". Now all the errors are getting reported.
    thx!

  • ✓ not output correctly from DOM parser

    Need a small help again.
    in my original XMl file, I have an entity &#671;
    It represents(ALT 671) a check symbol(a box).
    But the output XMl file from my DOMparser represents it as a question mark, which is NOT what I want.
    I'm using DOM parser with JAXP API to parse the XML file.
    Could you help me why does my parser doesn't output correct character for this particular entity only?
    Any suggestion is grately appreciated.
    -Srivalli.

    Thanks DrClap for your reply.
    Here is the statement in my DTD...
    <!ENTITY check     "&#10003;">
    (I had 671 in the place of 10003, but neither worked!!!!)
    This is a statement in input XML...
    The foll &check; owing is
    This is my Output XML....
    The foll ? owing is
    Here is the code in my java file where I didnot explicitly specify any output encoding type....
    DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setIgnoringElementContentWhitespace(true);
    DocumentBuilder builder=factory.newDocumentBuilder();
    currDocument=builder.parse(f);
    TransformerFactory tf=TransformerFactory.newInstance();
    Transformer t = tf.newTransformer(new StreamSource("transformoutput.xsl"));
    t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "nmstat.dtd");
    FileWriter fileOut = new FileWriter("outputAnno.xml");
    t.transform(new DOMSource(document), new StreamResult(fileOut));
    This is the code in transformoutput.xsl...
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
    <xsl:copy-of select="node()"/>
    </xsl:template>
    </xsl:stylesheet>
    Could you help me figuring out the problem.
    Thank you very much.
    -Srivalli.

  • Unknown traps from EEM - parsing in Spectrum

    I have a Cat6509 device sending EEM traps to our CA Spectrum monitoring system.
    I've downloaded, compiled, and loaded the EEM MIB from Cisco, but some of the traps coming in aren't being parsed, as their OIDs don't map to the EEM MIB.
    This is the "Unknown trap" that Spectrum sees:
    Unknown alert received from device uwb485as0101.us.net.intra of type SwCiscoIOS. Device Time 288+16:21:43. (Trap type 1.3.6.1.4.1.9.10.91.6.2)
    Trap var bind data:
    OID:  1.3.6.1.4.1.9.10.91.1.2.3.1.2.397  Value:  71
    OID:  1.3.6.1.4.1.9.10.91.1.2.3.1.3.397  Value:  0
    OID:  1.3.6.1.4.1.9.10.91.1.2.3.1.4.397  Value:  0
    OID:  1.3.6.1.4.1.9.10.91.1.2.3.1.5.397  Value:  0
    OID:  1.3.6.1.4.1.9.10.91.1.2.3.1.7.397  Value:  EEM Policy Director
    OID:  1.3.6.1.4.1.9.10.91.1.2.3.1.11.397  Value:  Output packet Drops on GigabitEthernet2/21 are incrementing by more than 10
    (The text in the last line is just for testing, and isn't necessarily the actual message.)
    The EEM MIB only goes up to 1.3.6.1.4.1.9.10.91.3, so Spectrum isn't handling this trap as we would like.
    Thank you for any guidance you can provide.
    Joe

    This looks like a potential problem with your NMS.  It looks like maybe it's building the trap OID incorrectly.  The 6.2 looks like the generic trap number and specific trap number (i.e. cEventMgrPolicyEvent).  Post a sniffer trace of the raw trap to confirm if the device is sending the wrong trap.

  • Cannot create controls/constants/indicators from XML parser

    Is there any reason I cannot create (by right clicking) a control/constant/indicator of a XML ref from the XML parser function? I need to make subvi's to build/read xml files, and that is really impossible without that ability.
    Labview 2012 f3
    Solved!
    Go to Solution.

    This bug has already been reported (CAR 357092), and is scheduled to be fixed in the next service pack release. For now, here's a workaround:
    1. Create a reference indicator from Functions » Programming » File I/O » XML » XML Parser » New.vi.
    2. Right click on the new "DOM Document Out" indicator terminal and select Create > Control (or Indicator).
    3. Right click on the new control/indicator and choose Select XML Parser Class. Then, you can select whatever class you need.
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • Don't understand error message from HTML parser?

    I've written a simple test program to parse a simple html file.
    Everything works fine accept for the <img src="test.gif"> tag.
    It understands the img tag and the handleSimpleTag gets called.
    I can even pick out the src attribute. But I get a very strange error message.
    When I run the test program below on the test.html file (also below) I get the following output:
    handleError(134) = req.att srcimg?
    What does "req.att srcimg?" mean?!?!?
    /John
    This is my test program:
    import javax.swing.text.html.*;
    import javax.swing.text.*;
    import javax.swing.text.html.parser.*;
    import java.io.*;
    public class htmltest extends HTMLEditorKit.ParserCallback
    public htmltest()
       super();
    public void handleError(String errorMsg, int pos)
       System.err.println("handleError("+pos+") = " + errorMsg);
    static public void main (String[] argv) throws Exception
        Reader reader = new FileReader("test.html");
        new ParserDelegator().parse(reader, new htmltest(), false);
    This is the "test.html" file
    <html>
    <head>
    </head>
    <body>
    This is a plain text.<br>
    This is <b>bold</b> and this is <i>itallic</i>!<br>
    <img src="test.gif">
    "This >is also a plain test text."<br>
    </body>
    </html>
    ----------------------------------------------------------------------

    The handleError() method is not well documented any more than whole javax.swing.text.html package and its design structure. You can ignore the behavior of the method if other result of the parser and your HTML file are proper.

Maybe you are looking for