XML DocumentBuilder.parse()

It seems that every example given is reading XML from a file. But if what I have is a String, and I do not want to write it to a file, how should I use this function?
Thanks.

Use a java.io.StringReader in the constructor of a org.xml.sax.InputSource object. This object can be used in methods such as org.apache.xerces.parsers.SAXParser.parse(InputSource)

Similar Messages

  • URGENT:  javax.xml.parsers.DocumentBuilder.parse() method issue

    Hi folks,
    I have an urgent parsing problem. I developed an app with JDK1.4 and now it needs to run on JDK1.3.1. The problem is this:
    If I use the DocumentBuilder.parse() method shipped with JDK1.4 it will parse a document containing namespaces WITHOUT a namespace declaration in the root element. However, since XML support doesn't ship with JDK1.3.1 I need to use JAXP. If I try this with the DocumentBuilder.parse() version shipped with JAXP (latest version) the parse method throws a NullPointerException. If I put the namespace declaration in the document it will parse fine. I tried setting the DocumentBuilderFactory.setNamespaceAware() explicitly to false (should be the default) but no luck. Any ideas other than adding the declaration (long story why I don't want it there...)
    thanks

    example, with declaration of namespace:
    <?xml version="1.0" encoding="UTF-8"?>
    <pre:root xmlns:inn="http://blablabla/inn/version/1.0/">
    <pre:metadata>
    <pre:dublin-core>
    <pre:title>mytitle</pre:title>
    <pre:description>mydesc</pre:description>
    <pre:creator>bjmann</pre:creator>
    </inn:dublin-core>
    </pre:root>
    example, without declaration:
    <?xml version="1.0" encoding="UTF-8"?>
    <pre:root>
    <pre:metadata>
    <pre:dublin-core>
    <pre:title>mytitle</pre:title>
    <pre:description>mydesc</pre:description>
    <pre:creator>bjmann</pre:creator>
    </inn:dublin-core>
    </pre:root>
    this may help...

  • Java.lang.NullPointerException javax.xml.parsers.DocumentBuilder.parse

    Hi all,
    i have a problem by solving an error in my code. The Code is mainly from Ian Darwin.
    The code i am running works with j2sdk1.4.2_04. But now i have to bring it to work with jdk1.6.0_13.
    The code parses xml documents. With small xml documents the code works. With large xml documents i get the following error while running the produced class file.
    Exception in thread "main" java.lang.NullPointerException
    at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.setChunkIndex(DeferredDocumentImpl.java:1944)
    at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.appendChild(DeferredDocumentImpl.java:644)
    at com.sun.org.apache.xerces.internal.parsers.AbstractDOMParser.characters(AbstractDOMParser.java:1191)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.characters(XMLDTDValidator.java:862)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:463)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
    at XParse.parse(XParse.java:38)
    at XParse$JFileChooserrv.<init>(XParse.java:119)
    at XParse.main(XParse.java:213)
    I know what a java.lang.NullPointerException mens. But i don't know where i have to look for. Specially i don't know what or where "com.sun.org.apache...." is.
    Is there a package that a have to add to the environment? Can some one tell my where i can find this package?
    I wrote the code for some years ago, 2006 or so. With the knew jdk1.6.0_13 some thinks chance in the environment. Couldn't find what exactly.
    The code has only 215 lines, but some how i can't add it to this Message, because Maximum allowed is only 7500.
    Is there an other Forum, which may is better for my question?

    Here is the code:
    import java.io.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.Container;
    import javax.swing.JTextArea;
    * This code is mainly from @author Ian Darwin, [email protected]
    public class XParse {
         /** Convert the file */
         public static void parse(File file, boolean validate) {
              try {
                   System.err.println("");
                   String fileName = file.getAbsolutePath();
                   System.err.println("Parsing " + fileName + "...");
                   // Make the document a URL so relative DTD works.
                   //String uri = new File(fileName).getAbsolutePath();
                   //System.err.println(uri);
                   DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
                   if (validate)
                   f.setValidating(true);
                   DocumentBuilder p = f.newDocumentBuilder();
                   p.setErrorHandler(new MyErrorHandler(System.err));
                   //XmlDocument doc = XmlDocument.createXMLDocument(file);
                   boolean vaild =  p.isValidating();
                   if (vaild) {
                        System.out.println("yes parsing");
                        Document doc = p.parse(file); // <<<< ERROR
                   System.out.println("Parsed OK");
              } catch (SAXParseException ex) {
                   System.err.println("+================================+");
                   System.err.println("|       *SAX Parse Error*        |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   System.err.println("At line " + ex.getLineNumber());
                   System.err.println("+================================+");
              } /**catch (RuntimeException ex) {
                   System.err.println("+================================+");
                   System.err.println("|       *SAX Parse Error*        |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   //System.err.println("At line " + ex.getLineNumber());
                   //System.err.println("At line " + ex.getMessage());
                   System.err.println("+================================+");
              }**/ catch (SAXException ex) {
                   System.err.println("+================================+");
                   System.err.println("|          *SAX Error*           |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
                   System.err.println("+================================+");
              /*}} catch (SAXNotRecognizedException  ex) {
                   System.err.println(" no SAX");*/
              } catch (ParserConfigurationException ex) {
                   System.err.println(" ???");
               } catch (IOException ex) {
                   System.err.println("+================================+");
                   System.err.println("|           *XML Error*          |");
                   System.err.println("+================================+");
                   System.err.println(ex.toString());
    private static class JFileChooserrv {
         JFileChooserrv(JFrame f, boolean vverabreiten) {
              String openfile;
              String verror;
              boolean validate = true;
              final JFrame frame = f;
              String vFilename = "Z:\\Boorberg\\parsen_vista\\daten";
              //String vFilename = "C:\\";
              File vFile = new File(vFilename);
              final JFileChooser chooser = new JFileChooser(vFile);
              JFileFilter filter = new JFileFilter();
              filter.addType("xml");
              filter.addType("sgml");
              filter.addType("html");
              filter.addType("java");
              filter.setDescription("strukturfiles");
              chooser.addChoosableFileFilter(filter);
              boolean vjeas = true;
              chooser.setMultiSelectionEnabled(vjeas);
              int returnVal = chooser.showOpenDialog(frame);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                   //Array  filearry[] = chooser.getSelectedFiles();
                   //if (vFile = chooser.getSelectedFiles()) {
                   //File  file[] = chooser.getSelectedFiles();
                   File  vfile[] = chooser.getSelectedFiles();
                   //String openfile = new String();
                   int vlenght = vfile.length;
                   if (vlenght>1) {
                        int x=0;
                        while (x< vlenght) {
                                  parse(vfile[x], validate);
                                  x = x +1;
                   if (vlenght<=1) {
                        File v2file = chooser.getSelectedFile();
                             parse(v2file, validate);
              } else {
                   System.out.println("You did not choose a filesystem           object.");
         System.exit(0);
    private static class JFileFilter extends javax.swing.filechooser.FileFilter {
         protected String description, vnew;
         protected ArrayList<String> exts = new ArrayList<String>();
         protected boolean vtrue;
         public void addType(String s) {
              exts.add(s);
         /** Return true if the given file is accepted by this filter. */
         public boolean accept(File f) {
              // Little trick: if you don't do this, only directory names
              // ending in one of the extentions appear in the window.
              if (f.isDirectory()) {
                   return true;
              } else if (f.isFile()) {
                   Iterator it = exts.iterator();
                   while (it.hasNext()) {
                        if (f.getName().endsWith((String)it.next()))
                             return true;
              // A file that didn't match, or a weirdo (e.g. UNIX device file?).
              return false;
         /** Set the printable description of this filter. */
         public void setDescription(String s) {
              description = s;
         /** Return the printable description of this filter. */
         public String getDescription() {
              return description;
    private static class MyErrorHandler implements ErrorHandler {
            // Error handler output goes here
            private PrintStream out;
            MyErrorHandler(PrintStream out) {
                this.out = out;
             * Returns a string describing parse exception details
            private String getParseExceptionInfo(SAXParseException spe) {
                String systemId = spe.getSystemId();
                if (systemId == null) {
                    systemId = "null";
                String info = "URI=" + systemId +
                    " Line=" + spe.getLineNumber() +
                    ": " + spe.getMessage();
                return info;
            // The following methods are standard SAX ErrorHandler methods.
            // See SAX documentation for more info.
            public void warning(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                //out.println("Warning: " + getParseExceptionInfo(spe));
            public void error(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                String message = "Error: " + getParseExceptionInfo(spe);
                throw new SAXException(message);
            public void fatalError(SAXParseException spe) throws SAXException {
                   //System.exit(0);
                String message = "Fatal Error: " + getParseExceptionInfo(spe);
                throw new SAXException(message);
         public static void main(String[] av) {
              JFrame vframe = new JFrame("chose files to pars");
              boolean vverabreiten = true;
              boolean validate = true;
              JFileChooserrv vdateienwaehlen = new JFileChooserrv(vframe, vverabreiten);
    }The Stack Trace i posted in the last Message. But i couldn't read it, i am not a programmer.

  • DocumentBuilder parser, DOM doucment object from a XML file error

    Hi guys
    I created a program which parses a xml and creates a DOM document object from
    it. The parser is validating.
    class xmlParser
        //create arrylist to store employee in
        private ArrayList<Employee> employeeStore = new ArrayList<Employee>();
        private DocumentBuilder parser;
        private static Document document;     
        //create an instant of Employee to be added to the arraylist
        private Employee theEmployee = new Employee();
        //create an instant of Address to be added to Employee to again be
        //added to Employee
        private Address employeeAddress = new Address();
        public xmlParser()
        public xmlParser(String myfile) throws IOException 
              //validate the XML document agaisnt the given dtd
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              factory.setValidating(true);
              factory.setIgnoringElementContentWhitespace(true);
              try {
                  parser = factory.newDocumentBuilder();
              }catch(javax.xml.parsers.ParserConfigurationException d) {
                   System.out.println("error with new document builder");
              //create document object (DOM tree) from xml file
              try {
                  document = parser.parse(new File(myfile));
              }catch(org.xml.sax.SAXException e) {
                  System.out.println("Error with parser file still creating xml personnel2");
        } In my main method when i call:
    xmlParser parsertree = new xmlParser("personnel.xml"); the exception keeps getting thrown and i get my my message back "Error with parser file still creating xml personnel2"
    Can't seem to figure it out, any ideas would be great.
    Thanks alot

    Hi,
    A - Check that the xml file is located in the same directory where you
    run your app.
    B - Check that the xml file is correct (in XML way).
    Suggestion : you may print the exception message, it might help.
    Hope that help,
    Jack

  • DocumentBuilder.parse classpath problem

    Hi, I've the "xerces.jar" in my classpath, and
    I'm using it like this:
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.servlet.http.HttpServletRequest;
    import org.xml.sax.helpers.DefaultHandler;
    import org.xml.sax.SAXException;
    //... etc..
    Document mapDoc = null;
    Element mapRoot = null;
    try {
    DocumentBuilderFactory docbuilderfactory =
    DocumentBuilderFactory.newInstance();
    DocumentBuilder docbuilder = docbuilderfactory.newDocumentBuilder();
    mapDoc = docbuilder.parse("/usr/home/tomsicp/site.xml");
    //..... etc
    The file compiles just fine, but when I run it on a
    "SunOS 5.8 sun4u sparc, Ultra-60" I'm getting
    "java.lang.NoClassDefFoundError: org/xml/sax/InputSource
    at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
    at <linenumber in my file>
    When I run it on a "Linux 2.4.7-10smp #1"
    everything is just fine.
    I've got the exact same profile on both boxes, and the xerces.jar
    file is exactly the same.
    Any thoughts on why this is happening?
    thanks,
    Paul

    what JDK do you use on each machine?

  • XML newbie - parsing RSS

    Hello Everbody,
    i started playing around with xml and i am finding it very interesting...i have a question, how does one transform an rss feed using Java.(to use on my home page for example)? I know that they have an RSSUtilities package here on java.sun.com but i wanted to try it out on my own so that i get more experience using it..
    i was successfully able to parse xml docs using sax and dom approaches..(i use jaxp by the way..) also, i can transform xml to html using dom and xslt stylesheets but feeds?? if i use the same program that i used for sml files, at run time i get the following errors..
    Error: URI=file:D:/javapractice/inrss.xml Line=2: Element type "rss" is n
    ot declared.
    Error: URI=file:D:/javapractice/inrss.xml Line=2: Attribute "version" is
    not declared for element "rss".
    Error: URI=file:D:/javapractice/inrss.xml Line=3: Element type "channel"
    is not declared.
    Error: URI=file:D:/javapractice/inrss.xml Line=4: Element type "title" is
    not declared.
    Error: URI=file:D:/javapractice/inrss.xml Line=5: Element type "link" is
    not declared.
    Error: URI=file:D:/javapractice/inrss.xml Line=6: Element type "descripti
    on" is not declared.
    Error: URI=file:D://javapractice/inrss.xml Line=7: Element type "language"
    is not declared.
    Error: URI=file:D://javapractice/inrss.xml Line=8: Element type "pubDate"
    is not declared.
    Error: URI=file:D://javapractice/inrss.xml Line=9: Element type "copyright
    " is not declared.
    Error: URI=file:D://javapractice/inrss.xml Line=10: Element type "image" i
    s not declared.
    i think the above is understood because there is no dtd for these rss feeds... please, help me understand this as i am going crazy with this problem

    Hi Nachida,
    The code is very simple and I am posting it as below.. Please note that if I use a regular xml file, it gives me correct results but if I use an RSS feed, it complains..
    First the code..
    import org.xml.sax.helpers.DefaultHandler;
    import java.io.File;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.DOMException;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import javax.xml.parsers.ParserConfigurationException;
    import java.io.IOException;
    public class TransformRss
    { Document document;
         public TransformRss()
              {try
                   {DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                     dbFactory.setValidating(true);
                    dbFactory.setIgnoringElementContentWhitespace(true);
                    DocumentBuilder documentBuilder = dbFactory.newDocumentBuilder();
                    document = documentBuilder.parse(new File("inrss.xml"));
              catch (SAXException e)
              {System.out.println("This is a SAX Exception");
              catch (ParserConfigurationException e)
              {System.out.println("This is a Parser Configuration Exception");
              catch (IOException e)
              {System.out.println("This is a IO Exception");
         public void transformTheDocument(File stylesheet)
              {try
                   {Transformer transformer = TransformerFactory.newInstance().newTransformer(new                 StreamSource(stylesheet));
                    transformer.transform(new DOMSource(document), new StreamResult( new File("alteredRss.html")));
              catch (TransformerConfigurationException e)
                   {System.out.println("This a transformer configuration exception");
              catch (TransformerException e)
                   {System.out.println(" this is a transformer exception");
         public static void main(String[] args) throws Exception
              {TransformRss transformRss = new TransformRss();
               transformRss.transformTheDocument(new File("program.xsl"));
    Now instead of rss.xml if I want to transform lets say resumexml.xml it works fine... I am posting both resumexml.xml and inrss.xml
    resumexml.xml-----------------------------------------------------------------------------------------
    <?xml version="1.0"?>
    <!DOCTYPE resume [
    <!ELEMENT resume (name, education, country)>
    <!ELEMENT name (#PCDATA)>
    <!ELEMENT education (#PCDATA)>
    <!ELEMENT country (#PCDATA)>
    ]>
    <resume>
    <name>sabrang</name>
    <education> engineer </education>
    <country> usa </country>
    </resume>
    inrss.xml--------------------------------------// or it could be any rss type of file...
    <?xml version="1.0" ?>
    <rss version="0.91">
    <channel>
    <title>rediff Top Stories - India</title>
    <link>http://www.rediff.com/</link>
    <description>India's largest news and entertainment service online.</description>
    <language>en-us</language>
    <pubDate>Sat, 10 Apr 2004 19:44:36 GMT</pubDate>
    <copyright>Copyright: (C) 2004 Rediff.com India Limited. All Rights Reserved.</copyright>
    <image>
    <title>rediff.com</title>
    <url>http://www.rediff.com/uim/red_log.gif</url>
    <link>http://www.rediff.com/</link>
    <width>144</width>
    <height>28</height>
    <description>Visit rediff.com</description>
    </image>
    <item>
    <title>I am a Bihari by birth, saysVajpayee</title>
    <link>http://www.rediff.com/rss/redirect.php?url=http://www.rediff.com/election/2004/apr/10pm.htm</link>
    <description>'I am a Bihari by birth. I was named Bihari by my father the day I was born,' the prime minister said in Patna.</description>
    </item>
    <item>
    <title>US army asks for ceasefire in Fallujah</title>
    <link>http://www.rediff.com/rss/redirect.php?url=http://www.rediff.com/news/2004/apr/10iraq.htm</link>
    <description>After more than a week of fighting the US army has occupied only a small portion of the town.</description>
    </item>
    <item>
    <title>'We'd like to have a Shoaib in our side' </title>
    <link>http://www.rediff.com/rss/redirect.php?url=http://www.rediff.com/cricket/2004/apr/10inter.htm</link>
    <description>India coach John Wright analyses the tour of Pakistan and discusses his future with the Indian team.</description>
    </item>
    <item>
    <title>Vaghela vs Vaghela in Kapadvanj</title>
    <link>http://www.rediff.com/rss/redirect.php?url=http://www.rediff.com/election/2004/apr/10guj1.htm</link>
    <description>Of the seven assembly segments in the constituency, four are with the BJP and the rest with the Congress. So, whichever way you look at it, it is going to be a contest of equals.</description>
    </item>
    <item>
    <title>Paes/Bhupathi give India 2-1 lead</title>
    <link>http://www.rediff.com/rss/redirect.php?url=http://www.rediff.com/sports/2004/apr/10doubles.htm</link>
    <description>The ace doubles pair beat Thomas Shimada and Takahiro Terachi in the doubles rubber of the Davis Cup Asia/Oceania Group I tie.</description>
    </item>
    <item>
    <title>On the road to peace, a dream bloodied</title>
    <link>http://www.rediff.com/rss/redirect.php?url=http://www.rediff.com/news/2004/apr/10uri.htm</link>
    <description>Just a few days back the prospects of the Srinagar-Muzzafarabad road reopening had looked bright.</description>
    </item>
    </channel>
    </rss>

  • Has anybody used DocumentBuilder.parse(URL)

    Hi friends
    Has anybody used DocumentBuilder.parse(URL) for make document object.
    I have the following piece of code
    <code>
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    System.out.println("| Start | Fetch xml"); // ------------ 1
    Document document = builder.parse("http://some url that gives back XML");
    System.out.println("| Stop | Fetch xml"); // ------------- 2
    </code>
    Now the problem is .. once in a while the code will hang at point 1 and will never reach point 2. Exception handling has been done.. but there are no exceptions being logged. The code simply hangs.
    Please let me know if you have also faced the same or similiar problem.
    Thanking in anticipation
    Partha.

    Is it similar with a file URL instead a http URL.
    Use
    Document document = builder.parse("file://c:/xmlFile");
    instead of
    Document document = builder.parse("http://some url that gives back XML");

  • Make DocumentBuilder.parse ignore DTD references

    Thanks to everyone in advance -
    So this issue looks to be pretty popular, I have found a few solutions, but nothing seems to stop the downloading of dtd files, for instance ones sitting up on w3.org.
    Here are some of the solutions i have found:
    http://stackoverflow.com/questions/155101/make-documentbuilder-parse-ignore-dtd-references
    http://forums.sun.com/thread.jspa?threadID=284209&forumID=34
    When I use this solution:
    myDocumentBuilder.setEntityResolver(new EntityResolver() {
              public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
                     throws SAXException, java.io.IOException
                if (publicId.equals("--myDTDpublicID--"))
                  // this deactivates the open office DTD
                  return new InputSource(new ByteArrayInputStream("<?xml version='1.0' encoding='UTF-8'?>".getBytes()));
                else return null;
    });it still continues to download the dtd.
    Any suggestions?
    Thanks,
    Sam

                        MyDocumentBuilder.setEntityResolver(
                             new EntityResolver() {
                                  public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws SAXException, java.io.IOException {
                                       if(true){
                                            throw new IOException(publicId +"|"+ systemId);
                                       return null ;
                        );Good eye - It looks like that IOException is never being called - any suggestions?
    Thanks,
    Sam

  • Optimizing DocumentBuilder.parse ??

    Hello,
    I am loading XML files and am finding that once they get into the range of 500 kb or so they get really slow to load. I stuck in a bunch of timing statement and have found DocumentBuilder.parse(file) is the guitly party.
    Does anyone know of any optimization possibilities for this or is this the nature of the beast? Is writing my own parser the only other option?
    Thanks,
    Shannon Goodman

    Yes, the larger and more complex the XML the longer it takes to parse. But writing your own parser is not the only option (and if it were I would still recommend against it, because it's more complicated than you think). XML is designed so that you can use any parser you like, and the one you are using is not the only one available. Look for others and try them out.

  • Eastern European characters in XML and parsing

    Hi all,
    I have a problem with XML parsing within Java code with special Eastern European characters.
    Whenever there is EE character within tags it reports:
    WARNING (12847): CORE3283: stderr: org.xml.sax.SAXParseException: The element type "CodeMeaning" must be terminated by the matching end-tag "</CodeMeaning>".
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:134)
    Obviously special character is in CodeMeaning XML tag. XML is well formed and syntactically OK and without special characters works OK. Does anyone have any suggestion how to force special characters in XML?

    Would you send a sample data for test? What is the encoding for your XML doc?

  • Variable xml and parser

    I have a String containing xml code and i want to parse ths string
    but method parse don't accept string so it returns "no protocol : String ".
    Could you helpe please, it's very important.
    my code (simplified):
    String entete_xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    String xml=entete_xml+"<aaa><bbb>aaaa</bbb><essai>reussi</essai></aaa>";
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    doc = builder.parse(xml);

    builder.parse(new InputSource(new StringReader(xml)));

  • XML SAX parser that support  LexicalHandler

    Hello,
    I'm looking for an XML SAX parser that support a LexicalHandler.
    I have xml files that are not well formed, ie: (&, <, >, etc...) characters within tags and I need to ignore them.
    Anyone have a link to some opensource library ??
    Thanks,
    Samir

    Don't waste your time. Using a LexicalHandler isn't going to help with parsing malformed XML. You should get the person who produced those files to replace them with correct XML.
    PC&#178;

  • Using XDKs XML Schema Parser

    I want to parse an XML schema(XSD file) and extract the types from it, ComplexType etc. Does anyone know to even begin this. Ive managed to parse and any XML file sucessfully returning all element types,names and values using the DOM parser but cant seem to find suitable methods in the oracle.xml.parser.schema library. I have started along these lines
    XSDBuilder bob =new XSDBuilder();
    XMLSchema sch = (XMLSchema)bob.build(url);
    where URL is string referencing the xsd file. But after that all I can get is the targetnamespace using
    String display = sch.getSchemaTargetNS();
    Any help greatly appreciated.

    Srinivas,
    Thanks for the reply. But that is not my requirement.Suppose I have a schema representing the following xml
    <Student>
    <Name>ABC</Name>
    <Class>XYZ</Class>
    <Course>PQR</Course>
    </Student>
    When I parse the XML Schema representing the above XML, it should give me a Java object that represents this XML structure. (Similar to Document object that is obtained when we an XML is parsed)
    Hope this is more clear.

  • XML C++ Parser in Solaris 2.6 could not parse with encoding UTF-16

    I tried to use UTF-16 encoding in the XML C++ Parser in Solaris 2.6.
    xmlinit() fails and returns error 201 - i.e.Unknown encoding. Though the ORACLE documentation has many encodings including UTF-16. Quite a few of these encodings are not working.
    Can any one help about UTF-16.
    Thanks
    Vijay Kumar

    Do you have Oracle's NLS data files?

  • XML C++ Parser in Solaris 2.6 could not parse with base64

    I am using XML C++ Parser (version 2.0.4) in Solaris 2.6
    I am using the following definition in dtd file to process binary data.
    <!ELEMENT Agent (base64)>
    I have two problem from xmlparse() function.
    1. This declaration always produces a warning:
    LPX-00103: warning: document structure does not match DTD.
    2. This causes the parser to fail completely if the corresponding data is empty. This field needs to be optional.
    Any ideas how to handle this situation.
    Thanks in advance
    Vijay Kumar

    You can either turn off validation or read section 3.2 of http://www.w3.org/TR/1998/REC-xml-19980210 on how to write a proper DTD.
    null

Maybe you are looking for

  • Camera Raw 4.6 not working with D700

    I have a PC with Windows XP Pro, 1 GB of RAM and Service Pack 2, Photoshop CS3 and the latest version of Camera Raw 4.6 When I open ACR, it does show that I am using Camera Raw 4.6 Beta version and it seems to work properly with my Nikon D200 NEF fil

  • Photo slideshow does not work?

    I tried numerous times to make the photo slideshow feature on ipod working it still does not work. I tried with different folders and albums. What happens is I set up all the photo slideshow settings on the ipod, select the first picture in the album

  • A user can only see the public area in a collaboration room

    Hi all, We have experienced that a certain user can only see the public area of a collaboration room although the user has member rights to see more content. We have tried to remove the user from the room and add him again. It did not help. Other use

  • Cs4: possible to assign shortcut to "rotate view" tool?

    Just wondering if we can assign a keyboard shortcut to the rotate view tool button. I can't seem to find where under the keyboard shortcuts pannel...

  • Chinese language not support in N93i...

    hi.. i have trouble with my nokia N93i, is it anyone here using nokia N93i with chinese word inside.. coz my phone is not support chinese language, i already update my fone but still don't have chinese language.. anyone here can help me??