DOM and XERCES

Hi Friends,
I am using ECLIPSE IDE and writing a java class using DOM and XERCES
to traverse through an xml file which is already stored in the local drive by hard coding the path in the code.
and this is working fine.
But now i want to traverse an Active Document (an xml file that is already opened when u launch an Eclipse application) so.. is there any method in DOM to access or traverse through the current Active Document ?
if there is please let me know.. it's urgent.. help me on this please.
Thanks in advance,
-Karthik

Can u send me the code. You might have missed out something on reading that XML .

Similar Messages

  • Difference between DOM and SAX

    Difference between DOM and SAX

    a sax parser is event driven meaning it processes the xml as it sees it and then forgets about it.
    you have to implement what you want the parser to do wants it reaches a certain event
    dom on the other hand keeps the whole structure of the message in memory as a tree.
    so there are strengths and weaknesses in both.
    you have to evaluate what you need

  • Delete elements from XML file using DOM and java

    Hi
    I want now is to remove element from my XML file
    for example
    i have following xml
    <?xml version="1.0" encoding="UTF-8"?>
    <printing>
    <firstLineTexts>
              <firstLineText />
              <firstLineText>|line11</firstLineText>
              <firstLineText>|line12</firstLineText>
    </firstLineTexts>
    </printing>how do i remove all elements fireLineText
    my final output should be
    <?xml version="1.0" encoding="UTF-8"?>
    <printing>
    <firstLineTexts>
    </firstLineTexts>
    </printing>How do i do it using DOM,
    I can create instance of DOM and write it using TransformerFactory
    Ashish

    Hi
    I am trying the following code,
    but it is not working
                    NodeList nScene = doc.getElementsByTagName("firstLineTexts");
              NodeList nScene1 = nScene.item(0).getChildNodes();
              for (int i = 0; i < nScene1.getLength(); i++)
                   Node n = nScene1.item(i);
                        nScene.item(0).removeChild(n);
              }

  • XALAN and XERCES on WL6

    Hi!
    I just can't get WLS6.0 to use new versions of XALAN and XERCES. I keep
    getting errors that are obviously because Weblogic is loading an older
    version of XALAN before my app ever gets loaded, and as a result I'm having
    trouble with <xsl:param> and <xsl:variable> tags not being able to recognise
    other params and variables in the top level scope. This is crucial to my
    application but after a day of messing around with everything from
    classpaths to startweblogic.cmd, I'm pretty much stuck.
    Does ANYONE know how to fix this?
    TIA,
    Navneet

    Hmm.. what's this I'm hearing about an XML registry for weblogic?
    "Jeffrey Winter" <[email protected]> wrote in message
    news:3ae702c5$[email protected]..
    >
    If you put the latest xerces.jar and xalan.jar file before anything elsein the
    CLASSPATH in your startup command file it will work. I'm doing in rightnow with
    Xerces 1.3.1 and Xalan 2.0.1.
    If you're trying to use JAXP however, you'll have problems because WLalways returns
    their own internal version of the DocumentBuilderFactory even if you putthe JAXP
    1.1 jar file in the class path and specify theorg.apache.xerces.jaxp.DocumentBuilderFactory
    in your registry.
    We got around this by defining a stub subclass of DocumentBuilderFactoryand instantiating
    is directly instead of through DocumentBuilderFactory.newInstance(). It'sa pain,
    but after that you can get around using the older versions that they'vebaked
    in.

  • [svn:fx-trunk] 7796: get the correct locales of batik and xerces jars into the build

    Revision: 7796
    Author:   [email protected]
    Date:     2009-06-12 13:01:48 -0700 (Fri, 12 Jun 2009)
    Log Message:
    get the correct locales of batik and xerces jars into the build
    bug: https://bugs.adobe.com/jira/browse/SDK-21565
    qa: i18n team (make sure they're all there)
    checkintests: pass
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-21565
    Modified Paths:
        flex/sdk/trunk/build.xml

    Originally posted by: rosec.messagingdirect.com
    I'll look into it; I'm a bit under the gun here and can't easily upend
    my development environment at this time, but hopefully I can look into
    it early next week. Thanks for the pointer.
    Daniel Megert wrote:
    > Chris Rose wrote:
    >> I don't know if this has been asked before (and you'd be amazed at how
    >> hard it is to find specific information when your search query is
    >> "eclipse 100% cpu usage opening class files in a jar"!) but, well,
    >> that's what I'm getting:
    >>
    >> When I open a class file in the editor that is contained in a jar file
    >> anywhere on a Java project's classpath, one of my processor pegs at
    >> 100% usage for anywhere from 15-120 seconds and eclipse becomes
    >> non-responsive for that period of time, not even redrawing the UI.
    >>
    >> This occurs for jars as large as the jboss client jar and the weblogic
    >> 80Mb uber-jar and for jars as small as a 241kb library jar.
    >>
    >> Is there anything I can do to track down WHY this is happening? I end
    >> up having to trace into third party code a lot while debugging
    >> container behaviour and this plays merry havoc with the timeouts for
    >> remote calls, so I'm quite motivated to suss out why it's happening.
    >>
    >> Eclipse details are attached.
    > There was a bug regarding big JARs on the build path. Can you try
    > whether this still happens using 3.4 M7. If so, please file a bug report
    > with steps to reproduce. Also, please create some stack dumps while
    > waiting and attach them to the bug report.
    >
    > Dani
    Chris Rose
    Developer Planet Consulting Group
    (780) 577-8433
    [email protected]

  • Weblogic 8.1 with Xalan 2.6.1 and Xerces 2.6.2 ?!?

    Hi,
    I'm trying to use Xalan 2.6.1 and Xerces 2.6.2 with Weblogic 8.1SP2, but no result yet...
    I found docs on bea website:
    http://edocs.bea.com/wls/docs81/pdf/faq.pdf
    http://e-docs.bea.com/wls/docs81/xml/xml_admin.html
    where I found this:
    "Warning: In version 8.1 of WebLogic Server, you can plug in only the following versions of the Apache Xerces parser:
    Xerces 2.2.0
    Xerces 2.3.0
    Xerces 2.4.0
    In addition, you can plug in only those versions of the Apache Xalan transformer that are compatible with the preceding versions of the Apache Xerces parser."
    I can't find any solution to this?
    I tried various option:
    - xercesImpl2.6 in the classpath variable
    - xalan2.6.2 in the endorsed lib
    - registered factory impl names in xml registry
    - prefer web-inf set to true
    Errors result in following exception:
    - NoMethodFound (rhino classes inside weblogic.jar)
    - ClassCast (xalan/xerces conflicts)
    Any one has suggestions?
    Regards
    Leonardo

    According to that link your right it is not supported.
    Have you tried adding the xerces jars at the beginning of the classpath?

  • Weblogic and xerces and xalan

    I understand that xerces and xalan are a part of the weblogic's distribution.
    Will BEA also upgrade to newer versions of these softwares as they are available?
    If not how do I use newer versions of these softwares with weblogic.
    This is becoming a critical issue for us as I already see a remarkable difference
    in performance while doing transformations. The newer versions of xalan and xerces
    are performing much better with the same xml and xsl documents as compared to
    the previous versions.

    According to that link your right it is not supported.
    Have you tried adding the xerces jars at the beginning of the classpath?

  • JAXP(DOM) and schema's

    Is it possible to process a document with a schema with DOM. I know it is possible with SAX but i was not sure if it was with DOM and i didn't want to get started on something that is not possible. Althought i would expect that i can seeing as schema's are W3C's standard. Thank you.

    Hello one & all
    I have to parse two xml files (same format but different values) and print the mismatch, if any elementwise..
    I am trying to create dom for these two files butafter that not able to traverse the xml file element wise (as it is a complex file, nested elements ).
    can any one guide me appropriately how to do this.with steps.
    Its urgent.

  • [CDATA] not the same way read in DOM and SAX (DOM: O.K., SAX: not O.K.)

    I wrote a test application that reads a XML file. First method reads it via DOM in a Document object, second that reads it via SAX in a string. The output is almost the same but the character data is different:
    while the dom outout is as expected:
    <hap>EUSF</hap>
    <name><![CDATA[WADDELL&REED ADV BOND CL Y]]></name>
    the SAX output is different:
    <hap>EUSF</hap>
    <name>WADDELL&REED ADV BOND CL Y</name>
    as both elements have text data, only the second is enclosed in a <![CDATA]> value. The DOM output is the same as when displayed the XML in internet explorer, so i guess this is the correct result. but my SAX reader does not display the <![CDATA]> value ...
    to get the sax output i subclassed DefaultHandler and overwrote the methods like described in the Web Service Tutorial "Echoing an XML File with the SAX Parser" (http://java.sun.com/webservices/docs/ea2/tutorial/doc/JAXPSAX3.html#64190):
    * Overwrites super.
    * Receive notification of character data inside an element.
    public void characters(char buf[], int offset, int len) {
    String s = new String(buf, offset, len);
    if (!s.trim().equals("")) { //suppress output of characters that are all whitespace
    write(s);
    }//characters()
    the characters() method has the content of an element, but it has not the information if a CDATA is enclosing the data or not(?). How can this be done?

    There's a thing called a LexicalHandler (org.xml.sax.ext.LexicalHandler) that has startCDATA and endCDATA methods. The API documentation suggests that you could create your own LexicalHandler and use it somehow, but it doesn't give you a nicely packaged example. I don't have an example of it either, sorry.
    However despite what you say, those two outputs are not different. In XML terms they are identical and parsers will treat them identically.

  • Xalan and Xerces

    Where do I get the compatible versions of above jars to do XSL Transformations. Pls help... Tried to do lot of research and not able to do much. Lates Xalan does not have XSLTProcessor, XSLTProcessorFactory and XSLTInputSource. I tried to use older version of Xalan and found that Xerces is not compatible with it.

    Xalan-Java version 2.6.0 distribution includes xercesImpl.jar from Xerces-Java 2.6.2.
    http://xml.apache.org/xalan-j/

  • Differnce between java script xml dom and Java Xml dom

    Hi,
    In my application For client side in Java Script for craetion of DOM MIcrosoft Activex object is used. USing that one they are buiidng DOM. And they are saving as XML. In server side i have to write one servlet which will parse that xml and i have to store in dynamic arrays.Which API is better for parsing XML in java.In util pacakge which class is better for storing dynamical values that means MAP,Hash Map,Hash table ??

    in java, the java..xml.parsers package is generally used for parsing xml into a DOM. there are also sax and stax parsers available.
    which class in java.util is better for storing stuff depends on what you need to do with the stuff. find a nice tutorial on java collections and then decide which one makes sense for what you need.

  • Java servlet, DOM and xml help! please urgent!

    I have to write a servlet that takes the user input to build a xml document using DOM API and should be able to append new entry to that xml file whenever any user adds an entry. I have written the fillowing code, can anyone please take a look at this code and tell me the right way to do it as this code is actually not creating any xml file and also in commented line of this code I tried by giving blank xml file name with just root element, so that this code can enter new elements like name, title as child element of the root, but doesn't work.
    PrintWriter out = res.getWriter ();
    res.setContentType ("text/html");
    try
    Document xmldoc = null;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    DOMImplementation impl = builder.getDOMImplementation();
    // Document xmldoc = builder.parse(xmlfile name);
    Element e = null;
    Node n = null;
    String name = req.getParameter("name");
    String title = req.getParameter("title");
    String address = req.getParameter("address");
    xmldoc = impl.createDocument(null, "records", null);
    Element root = xmldoc.getDocumentElement();
    e = xmldoc.createElementNS(null, "name");
    n = xmldoc.createTextNode(name);
    e.appendChild(n);
    root.appendChild(e);
    e = xmldoc.createElementNS(null, "title");
    n = xmldoc.createTextNode(title);
    e.appendChild(n);
    root.appendChild(e);
    e = xmldoc.createElementNS(null, "address");
    n = xmldoc.createTextNode(address);
    e.appendChild(n);
    root.appendChild(e);
    DOMSource domSource = new DOMSource(xmldoc);
    Source xslSource = new StreamSource (xsl file);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer(xslSource);
    transformer.transform(domSource,new StreamResult (out));

    Document xmldoc = null;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    xmldoc = documentBuilder.newDocument();
    Element e = null;
    Node n = null;
    String name = req.getParameter("name");
    String title = req.getParameter("title");
    String address = req.getParameter("address");
    e = xmldoc.createElement("name");
    n = xmldoc.createTextNode(name);
    e.appendChild(n);
    xmldoc.appendChild(e);
    e = xmldoc.createElement("title");
    n = xmldoc.createTextNode(title);
    e.appendChild(n);
    xmldoc.appendChild(e);
    e = xmldoc.createElement("address");
    n = xmldoc.createTextNode(address);
    e.appendChild(n);
    xmldoc.appendChild(e);
    DOMSource domSource = new DOMSource(xmldoc);
    StreamSource xslSource = new StreamSource (xsl file);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer(xslSource);
    transformer.transform(domSource,new StreamResult (out));

  • DOM, and (not) sorting by Attribute name

    I'm using XML files to store certian options for a program I'm making. The only problem though is that it seems as though the NamedNodeMap you get from calling node.getAttributes has the attributes in sorted order.
    Namely it's sorted alphabetically.
    This is not at all what I would like, it's pretty important that the attributes be in the order I wrote them, not sorted.
    Is there another way I can do this?
    I could always just have a text entry for the Attribute types, like
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    AttributeType_1, AttributeType_2
    <whatever AttributeType_1="whatever" AttributeType_2>
    #And so on.
    </root>
    Or I could do any number of variations on that theme.

    Here is some source code.
    xmlGenerate.java
    This will convert 2D arrays into XML Strings, or vice versa. There's a couple other things it does too, but that's the important part (
    //import crap
    import java.sql.Savepoint;
    import java.util.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.xml.parsers.*;
    import javax.swing.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    import org.apache.xml.serialize.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    //generates xml files
    public class xmlGenerate{
    public static final String PATH=SRJava.Constants.PATH+
    "\\Editors\\CharacterGenerator\\";
    * This method takes in stuff, the kind of stuff,the names of the
    * attributes of that stuff, and returns XML
    * The input is the stuff, and the output is
    * a string which is the stuff in XML.
    * Each row of the stuff represents the data of an Object
    * Each column represents a specific value, which is specified by
    * attrNames
    public static String toXML(Object[][] stuff, String[] attrNames,
    String type){
    try{
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();
    Element root = document.createElement("root");
    document.appendChild(root);
    //going thru each equipment to append to root
    int entries = stuff.length;
    int attributes = attrNames.length;
    String tempStr;
    for (int entry = 0; entry < entries; entry++){
    Element a1 = document.createElement(type);
    //set xml document
    root.appendChild(a1);
    for (int attr =0; attr < attributes; attr++){                   
    //this gets the data from the xml
    if (stuff[entry][attr] instanceof String){
    tempStr=(String)stuff[entry][attr];
    }else{
    tempStr="";
    a1.setAttribute(attrNames[attr],tempStr);
    OutputFormat format = new OutputFormat(document, "UTF-8", true);
    StringWriter stringOut = new StringWriter();
    XMLSerializer serial = new XMLSerializer(stringOut, format);
    serial.asDOMSerializer();
    serial.serialize(document);
    return stringOut.toString();
    *fill in components
    }catch (Exception e){
    e.printStackTrace();
    return null;
    * From XML , returns the equipmennt
    * Input is file and output is the data from the XML document
    public static Object[][] fmXML(Node root){
    //make double array
    try{           
    NodeList childNodes = root.getChildNodes();
    Vector attrNodeVector= new Vector();
    int entries=0;
    boolean determined=false;
    NamedNodeMap attributeList = null;
    for (int index=0; index < childNodes.getLength(); index++){
    Node node=childNodes.item(index);
    if (node.getNodeType()==Node.ELEMENT_NODE){
    entries++;
    attrNodeVector.add(node);
    if (determined==false){
    attributeList=node.getAttributes();
    determined=true;
    String[] attrNames=getAttrNames(root);
    int attributes=attrNames.length;
    Object[][] stuff=new Object[entries+1][attributes];
    //this value is so new entries can be added.
    for (int attr=0; attr < attributes; attr++){
    stuff[0][attr]="";
    for (int entry = 0; entry < entries; entry++){
    Element thenode=(Element)attrNodeVector.get(entry);
    //make sure the node being looked at is the right kind.
    for (int attr=0; attr < attributes; attr++){
    //parseing goes on
    stuff[entry+1][attr] = thenode.getAttribute(attrNames[attr]);
    return stuff;
    }catch (Exception e){
    e.printStackTrace();
    //there was some kind of error, return nothing useful.
    return null;
    //sorts the Nodes
    private static Node[] sort(NodeList subsequent, String[] tags){
    Node[] sorted = new Node[tags.length];
    //looking through all the different nodes
    for(int x=0; x < subsequent.getLength(); x++){
    Node inOrder = subsequent.item(x);
    String tag = inOrder.getNodeName();
    for(int i=0; i<tags.length; i++){
    if(tag.equals(tags)){
    sorted[i] = inOrder;
    break;
    return sorted;
    * output the xml document to a file
    public static void save(String doc, String name){
    try {
    PrintWriter oF = new PrintWriter(new FileWriter(name), true);
    oF.print(doc);
    oF.close();
    catch (IOException x){
    System.err.println("There was a saving error");
    //retreiving some data from an xml file
    public static Node open(String file){
    try{
    //This code came from a guy called Rob Thorndyke.
    Document doc = DocumentBuilderFactory.newInstance()
    .newDocumentBuilder().newDocument();
    File f=new File(file);
    System.out.println(f.getPath());
    // Step 2 is to get a Transformer object.
    Transformer transformer =
    TransformerFactory.newInstance().newTransformer();
    // Step 3 is to set up Source and Result objects and use the
    // Transformer object to do the conversion.
    Source source = new StreamSource(new FileReader(file));
    Result result = new DOMResult(doc);
    transformer.transform(source, result);
    //This code did not.
    Node root = doc.getDocumentElement();
    if (root == null){               
    System.out.println("There is no root!");
    return null;
    return root;
    }catch (Exception e){
    System.out.println("Error in opening.");
    return null;
    public static String[] getAttrNames(Node root){
    try{           
    NodeList childNodes = root.getChildNodes();
    Vector attrNodeVector= new Vector();
    int entries=0;
    boolean determined=false;
    NamedNodeMap attributeList = null;
    for (int index=0; index < childNodes.getLength(); index++){
    Node node=childNodes.item(index);
    if (node.getNodeType()==Node.ELEMENT_NODE){
    entries++;
    attrNodeVector.add(node);
    if (determined==false){
    attributeList=node.getAttributes();
    determined=true;
    int attributes=attributeList.getLength();
    String[] attrNames = new String[attributes];
    //get the names of the attributes
    for (int attr=0; attr < attributes; attr++){
    attrNames[attr]=attributeList.item(attr).getNodeName();
    return attrNames;
    }catch(Exception e){
    System.out.println("Error in getting column names");
    return null;
    public static String getType(Node root){
    if (root == null){               
    System.out.println("There is no root!");
    return null;
    NodeList childNodes = root.getChildNodes();
    Vector attrNodeVector= new Vector();
    for (int index=0; index < childNodes.getLength(); index++){
    Node node=childNodes.item(index);
    if (node.getNodeType()==Node.ELEMENT_NODE){
    return node.getNodeName();
    return null;
    // main method
    public static void main(String[] args){
    System.out.println("Hello out there");
    //file->xml->equpment->object
    Node root=open(PATH+"\\Equipment.xml");
    Object[][] stuff = fmXML(root);
    //frames (GUI)
    JFrame aFrame = new JFrame();
    aFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    aFrame.addWindowListener(new WindowAdapter(){
    public void windowClosed(WindowEvent e){
    System.exit(0);
    JPanel aPanel = new JPanel();
    //set headers
    aFrame.getContentPane().add(aPanel);
    //create scrollableTable
    String[] columnNames=new String[] {
    "name",
    "conceal",
    "cost",
    "rating",
    "weight",
    "street index"
    boolean[] columnEditable= new boolean[]{
    true,
    true,
    true,
    true,
    true,
    true
    int[][] sliders = new int[][]{
    {-1,-1,-1},
    {-1,-1,-1},
    {-1,-1,-1},
    {-1,-1,-1},
    {-1,-1,-1},
    {-1,-1,-1}
    if (stuff== null){
    System.out.println("stuff is null");
    aPanel.add(new ScrollableTable(null,stuff,columnNames,columnEditable,
    sliders,true,0));
    aFrame.pack();
    aFrame.setLocationRelativeTo(null);
    aFrame.show();
    This isn't what I'm actually using, but I whipped it up real quick so you could get an idea about how it would be used.
    * Test.java
    * Created on March 23, 2003, 5:14 PM
    package SRJava;
    * @author unknown
    import org.w3c.dom.*;
    import SRJava.Editors.CharacterGenerator.*;
    import javax.swing.*;
    public class Test extends javax.swing.JFrame {
    /** Creates new form Test */
    public Test() {
    //Replace this with some other XML file, in a table like form.
    String fileName = "M:\\Shadowrun\\SRJava\\Editors"
    + "\\CharacterGenerator\\Equipment.xml";
    Node root = xmlGenerate.open(fileName);
    String[] columnNames = xmlGenerate.getAttrNames(root);
    Object[][] data = xmlGenerate.fmXML(root);
    //There should be no sliders, and all columns should be editable.
    int columns=columnNames.length;
    int[][] sliders = new int[columns][3];
    boolean[] columnEditable= new boolean[columns];
    for (int index=0; index < columns; index++){
    sliders[index][0]=-1;
    sliders[index][1]=-1;
    sliders[index][2]=-1;
    columnEditable[index]=true;
    Object[][] avail = new Object[][]{
    JScrollPane scroll = new JScrollPane();
    JTable table=new JTable(data,columnNames);
    scroll.setViewportView(table);
    getContentPane().add(scroll, java.awt.BorderLayout.CENTER);
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    pack();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    pack();
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
    System.exit(0);
    * @param args the command line arguments
    public static void main(String args[]) {
    new Test().show();
    // Variables declaration - do not modify
    // End of variables declaration
    And here's an XML File, call it Equipment.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <Equipment conceal="" name="" xloge="Blorg"/>
    <Equipment conceal="Bla" name="different sample" xloge="Great southern trendkilling"/>
    <Equipment conceal="adsf" name="sample" xloge="Red Crested"/>
    </root>

  • SAX parsers hanging (crimson and xerces) on InputStream

    Hi,
    While searching I've seen a lot of postings about sax parsers hanging on InputStreams. Many have no replies, some do. So far I've tried several fixes mentioned to no avail. I've seen it hang in the startDocument() and hang after reading the entire document. All sorts of hangs . . . Oh and in some situations it works fine, but that's not good enough.
    1. I tried wrapping the InputStream as described at the jdom.org FAQ with my own InputStream that hides the close() call. Then I pass my wrapper InputStream to the saxparser.parse() method. This didn't work, because you need to wrap SocketInputStream, not InputStream and SocketInputStream has package permissions which keep me from inheriting from it. If somebody can shed some light on how to do this, I'll try again, but for now that approach is shelved.
    2. I tried adding an EOF character, 0x1A, to the end of the xml string being sent over the socket. The parser still hangs.
    Any more suggestions?
    Thanks,
    Steve

    Here's a faq question and answer from jdom.org. Can anybody explain how to do this in more detail? He mentions two workarounds. I've done the second and it works fine, but I'd prefer to get the first workaround working instead -- the wrapper InputStream idea.
    Why does passing a document through a socket sometimes hang the parser?
    The problem is that several XML parsers close the input stream when they read EOF (-1). This is true of Xerces, which is JDOM's default parser. It is also true of Crimson. Unfortunately, closing a SocketInputStream closes the underlying SocketImpl, setting the file descriptor to null. The socket's output stream is useless after this, so your application will be unable to send a response. To workaround, protect your socket's input stream with an InputStream wrapper that doesn't close the underlying stream (override the close() method), or read everything into a buffer before handing off to the JDOM builder:
    byte[] buf = new byte[length];
    new DataInputStream(inputStream).readFully(buf);
    InputStream in = new ByteArrayInputStream(buf);
    (Contributed by Joseph Bowbeer)

  • DOM and Namespaces

    Hi,
    I have two XML schema documents. (A.xsd and B.xsd)
    Now i am parsing B.xsd using DOM. B.xsd has a definition like this :
    <xs:element ref="a:Employee"/>
    where 'a' is a namespace prefix. its actual definition is in A.xsd defined like this :
    <xs:element name="Employee" type="EmployeeType"/>
    While parsing B.xsd, I have found an element having reference to different namespace and the definitions are actully in different schema file.
    DOM content tree will have only the content of B.xsd. Are there any APIs to extract details of the elements defined in some other document / Namespaces??
    I am interested to fetch the 'type' attribute of the element. i.e., "EmployeeType"
    Can anyone please help me out in this regard. ?
    Regards,
    Guru Hanchinal

    Next release is planed to be out next week. We will annouced here when they are ready for download.

Maybe you are looking for