Sun stuffed up in XML DOM, any ideas?

hi all,
I do a lot of back end integration with embedded systems back to the
end user. A lot of my work is either server side or end user. As such
I use Swing quite a lot.
For a new import utility, I decided to use XML to configure the options
for the end user on a per client basis. This is for field mapping
configuration on a table per table basis.
During this, I have discovered what a dog XML in J2SE is.
But the biggest problem is something I consider a design flaw. Namely:
TransformerException
This Exception is actualy a wrapper of other exceptions. In my case I
am transforming either to or from a file, hence I can get IO exceptions.
There are no IO exceptions thrown, there is only a TransformerExcetion
(well technicaly there are TransformerExceptions thrown that wrap the
IO exceptions).
Because I am writing a tool for end users at factories (with limited
computer skills), I allways handle every single exception with an
intelligent way, normaly either fixing the problem myself or giving
a meaningful message to the user (this does not mean just doing a
e.toString() and placing it in a dialog box).
Well, there is no documentation that states the possible exceptions
that can be wrapped by TransformerException. If you look at all the
classes that implement javax.xml.transform.Source or
javax.xml.transform.Result you will see that in none of
them, is there any documentation on what exceptions can be thrown.
Btw, the exceptions are thrown when you call the method transform() from
javax.xml.transform.TransformerI presume I could try some sort of hash table with a list of all
exceptions in J2SE, and a static method to run when it occurs (using
reflection), but that would be incredibly UGLY.
Because the exceptions are wrapped, there is no error at compile time as
long as you handle the TransformerExcetion. So there is no way for me
to determine what could be thrown.
To me this breaks the whole concept of exceptions. When we hide the
exceptions that can occur and remove the need for a developer to
catch them, then why have them at all? This makes me feel like I'm
working in a 4GL or C.
Note that I posted this in the XML group and got very unhelpful responses.
Maybe I am just ranting, but I find it frustrating when something like
this is developed with such a web centric view, and no conception of
how it would impact on people in other areas of development. Of course
e.toString() would be fine in a log file for a server when a java
programmer is going to review the log. Not at all helpful for
end user software.
[end rant]
Anyway, anyone with any suggestions on how best to handle this?
James.

public class Test {
     public static void main(String[] args){
          try {
               throw new javax.xml.transform.TransformerException(
                    new java.rmi.AccessException("test")
          } catch (javax.xml.transform.TransformerException e){
               Throwable yuk = e.getException();
               try {
                    throw yuk;
               } catch(java.rmi.AccessException ae){
                    System.out.println("got it! [" + ae.toString() + "]");
               } catch(Throwable e22){
                    System.out.println("missed");
}

Similar Messages

  • Xml and hebrew, any ideas

    Hi all I am a prityy much "novice" in xml / xsl but I did some simple stuff. when I add a small hebrew word to my xml I got an exception
    " javax.xml.transform.TransformerException: An invalid XML character (Unicode: 0xf8) was found in the element content of the document."
    I use xalan.jar and xerces.jar
    any ideas
    thanx and by Yonatan

    Take a look at this thread:
    http://forums.java.sun.com/thread.jsp?forum=34&thread=155659&start=0&range=30#454205

  • WebDynpro 4 Java & Persistence options : Any Idea how 2 read an XML?

    Hi,
    I was wondering if there is an easy way to store modified (or new) values in a WebDynpro application.
    e.g. A User adds a new row to an existing Table UI in Web Dynpro application with create button. I want to save this row either in an XML file, in a table connecting to database or in an ABAP table via RFC connection. Which option is a light (on resources?) and easy to implement. I think it's reading and writing to an XML file. What are the other options, if any?
    I've been trying to read an xml file (stored under src/mimes/Components/<com.sap.myComp>/test.xml as below:
    //controller code
    private static final String FILE_NAME = "test.xml";
    private static final WDWebResourceType FILE_EXT = WDWebResourceType.XML;
    IWDResource resource = WDWebResource.getWebResource(wdComponentAPI.getDeployableObjectPart(), EditView.FILE_EXT, EditView.FILE_NAME);
    wdContext.currentContextElement().setFile(resource);
    //end controller code
    //view Init() code
    IWDResource resource = wdContext.currentContextElement().getFile();
    File file = new File(resource.getResourceName().toString());
    /* I've also tried below
            FileInputStream fis = null;
         fis = new FileInputStream(file);
            url = file.getAbsolutePath();
            //url is null when printed?
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(file);
    doc.getDocumentElement().normalize();
    content = doc.getDocumentElement().getNodeName().toString();
    //end view Init() code
    When I print the value of content, I get it's initial value which is null. What is wrong?? any ideas?
    How to get the correct path to the stored xml and how to display its contents? I've read enough posts on SDN but couldn't get it working.
    Appreciate your help.
    Regards,
    N.

    hi,
    U r retriving the elements by tag name.So it just chks the tag name ie.<book> & gives u array of elements.But u need retrive d attribute of <book> tag itself.
    =Solution =====
    Add one more statement ----> var[]= doc.getElementsByName("book");
    Now u hav book elements as an array & can retrive id in for loop
    for(var; var.length;var++)
    doc.element[var].id.value

  • I am trying to open a .xml file in FCP, when i try to import the file it says choose a translation document. Any ideas?, I am trying to open a .xml file in FCP, when i try to import the file it says choose a translation document. Any ideas?

    I am trying to import a .xml file into FCP; it asks for a translation document file. Any ideas on how to proceed? Thanks

    What kind of xml?  What kind of xml?
    Shane is right if it's an xml exported from finalcutpro but there are many other kinds/uses for xml, most of which will not import into fcp.

  • Sun ONE 4 hangs during installation....any ideas??

    Hi,
    i have installed JDK 1.4 on Windows Me OS. I did shut down and restart the computer. Now I am trying to install Sun ONE Studio 4 update 1, Community Edition. The installation process begins but then freezes at the point where the dialog box says:
    "Searching for suitable Java SDK. Please Wait..."
    I let it run all night only to wake up to the same thing on the screen 6 hours later!
    Any ideas on the cause/solution?
    Thanks.

    Where exactly did you install the JDK ?
    THe path to the JDK must not contain any blank spaces (so for examle C:\Program Files\... is not a suitable location) otherwise you may have trouble getting it to work.

  • Any idea where I can find sun.tools.java.Constants ?

    I've been playing around with all that syntax highlighting nonsense which seems to be a rite of passage around here. I came across the Sun version but they assume I know where to find
    sun.tools.java.Constants
    which, of course, I don't. Any ideas on where I can get this class?

    Thanks. I thought I'd looked there... still, only three bucks. Mind you, that example still isn't working.

  • Downloaded Yosemite on Macbook Pro, tried to install now computer is stuffed. Any ideas anyone?

    Hi, I have a 2011 Macbook Pro which was working fine until I tried to install Yosemite.
    It downloaded okay, but failed to install coming up with an error message that I cant recall.
    I have tried Internet Recovery, but the computer sat there with the countdown stuck at 24hrs, for 2 hours, got very hot and then came up with an exclamation mark over the globe icon and an error message which was 2002F I think. Any ideas anyone? I am trying to get back to OSX Mavericks and keep it that way until Apple sort themselves out.

    Try booting and holding down the "option" key and see if the old OS is still intact.
    Otherwise you'll have to go back to the old OS.
    Let us know and we'll walk you through either retrieving via "Target Disk Mode" or pulling the current hard drive.
    The first will require another Mac the second at least another drive and an external enclosure or a dongle.

  • Using Sun Web Server 6.1 from the IDE

    Using JSE 8 with Sun Web Server 6.1 set as the target container, I have a SUNWS61deployment.xml file created.
    That didn't exist in JSE 7. Is it WS 6.1 SP4 or SP5 -related ?
    I also have ws61-sun-web.xml with a simple <sun-web-app/> tag (empty deployment descriptor).
    What should this file contain? Is it a replacement for sun-web.xml?
    Do I still need sun-web.xml? Its DTD declaration sounds like Sun
    App Server 7 (http://www.sun.com/software/sunone/appserver/dtds/sun-web-app_2_3-1.dtd)
    So you have plans to make "Sun Resources" (pools, JNDI resources, ...) created in the IDE be registerable directly in the Web Server just like it's possible with the sun app server?
    How safe is it to use JSE 8 with an older Web Server Service Pack (say 6.1SP1)?

    SUNWS61deployment.xml is created bythe IDE to be used internally and not to be used by the developer. This file wouldn't be sent to webserver after deployment.
    The ws61-sun-web.xml is sun-web.xml only and yes it is same as it is in Appserver7 as the webcontainer for both Webserver6.1 and Appserver7 are same. After deployment to webserver, ws61-sun-web.xml is renamed to Webserver as sun-web.xml by the IDE. When opened the developer can edit in the XML editor.
    The reason for having it as ws61-sun-web.xml in IDE is to avoid the clash between sun-web.xml of Appserver8.1 which is J2EE1.4 based whereas Webserver6.1 Web container is J2EE1.3 based.
    It should be okay to use any service pack of Webserver6.1 with JSE8
    Hope this helps

  • How to Parse a string into an XML DOM ?

    Hi,
    I want to parse a String into an XML DOM. Not able to locate any parser which supports that. Any pointers to this?

    Download Xerces from xml.apache.org. Place the relevant JAR's on your classpath. Here is sample code to get a DOM document reference.
    - Saish
    public final class DomParser extends Object {
         // Class Variables //
         private static final DocumentBuilder builder;
         private static final String JAXP_SCHEMA_LANGUAGE =
             "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
         /** W3C schema definitions */
         private static final String W3C_XML_SCHEMA =
             "http://www.w3.org/2001/XMLSchema";
         // Constructors //
         static {
              try {
                   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                   factory.setNamespaceAware(true);
                   factory.setValidating(true);
                   factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                   builder = factory.newDocumentBuilder();
                   builder.setErrorHandler(new ErrorHandler() {
                       public void warning(SAXParseException e) throws SAXException {
                           System.err.println("[warning] "+e.getMessage());
                       public void error(SAXParseException e) throws SAXException {
                           System.err.println("[error] "+e.getMessage());
                       public void fatalError(SAXParseException e) throws SAXException {
                           System.err.println("[fatal error] "+e.getMessage());
                           throw new XmlParsingError("Fatal validation error", e);
              catch (ParserConfigurationException fatal) {
                   throw new ConfigurationError("Unable to create XML DOM document parser", fatal);
              catch (FactoryConfigurationError fatal) {
                   throw new ConfigurationError("Unable to create XML DOM document factory", fatal);
         private DomParser() {
              super();
         // Public Methods //
         public static final Document newDocument() {
              return builder.newDocument();
         public static final Document parseDocument(final InputStream in) {
              try {
                   return builder.parse(in);
              catch (SAXException e) {
                   throw new XmlParsingError("SAX exception during parsing.  Document is not well-formed or contains " +
                        "illegal characters", e);
              catch (IOException e) {
                   throw new XmlParsingError("Encountered I/O exception during parsing", e);
    }- Saish

  • XML DOM getDocumentElement() working in Java, not in Tomcat

    This is a really strange one (to me anyway) !
    We have some XML parsing classes tested in Eclipse that run just fine as Java code. When we try to use them in Tomcat, though, we get an error with getDocumentElement() - it always truncates at the beginning of the XML. This is the XML string we are using for testing in Eclipse:
    "<rft><pollcfg><tmo>200</tmo><retry>5</retry>"
              + "<mapping>"
              + "<name>Simulation</name>"
              + "<subnet>0</subnet>"
              + "<comm>com8</comm>"
              + "</mapping>"
              + "<comm>com11</comm>"
              + "<comm>com12</comm>"
              + "<subnet>1</subnet>"
              + "<subnet>2</subnet>"
              + "<subnet>3</subnet>"
              + "<subnet>4</subnet>"
              + "</rft>";
    And we load this string into a DOM as follows
                   DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                   dbf.setValidating(false);
                   dbf.setNamespaceAware(true);
                   dbf.setIgnoringElementContentWhitespace(true);
                   DocumentBuilder builder = dbf.newDocumentBuilder();
    ByteArrayInputStream bais = new ByteArrayInputStream(XMLRetrievedData.getBytes());
    doc = builder.parse(bais);
    ANd then we can say :
    System.out.println( "getDocumentElement() was " + doc.getDocumentElement() );
    and we get the XML.
    If we run this in Tomcat the line
    System.out.println( "getDocumentElement() was " + doc.getDocumentElement() );
    produces
    [rft: null]
    instead of the XML we get when we run the same code in Eclipse !!
    We want to parse the DOM, delete some elements and add some new elements. Then we want to return the altered DOM as a String .. for whatever client needs it.
    Any ideas about this ? What could be wrong ?
    Thanks !!

    Hi there,
    I've got the same problem, except it doesn't even work as a Java application... getDocumentElement() always returns null... any idea?
    I checked the classpath and tried several versions of Document/Element, but without success.
    Regards,
    Laurent.

  • XML DOM working in Java, not working in Tomcat

    This is a really strange one (to me anyway) !
    We have some XML parsing classes tested in Eclipse that run just fine as Java code. When we try to use them in Tomcat, though, we get an error with getDocumentElement() - it always truncates at the beginning of the XML. This is the XML string we are using for testing in Eclipse:
    "<rft><pollcfg><tmo>200</tmo><retry>5</retry>"
    + "<mapping>"
    + "<name>Simulation</name>"
    + "<subnet>0</subnet>"
    + "<comm>com8</comm>"
    + "</mapping>"
    + "<comm>com11</comm>"
    + "<comm>com12</comm>"
    + "<subnet>1</subnet>"
    + "<subnet>2</subnet>"
    + "<subnet>3</subnet>"
    + "<subnet>4</subnet>"
    + "</rft>";
    And we load this string into a DOM as follows
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setValidating(false);
    dbf.setNamespaceAware(true);
    dbf.setIgnoringElementContentWhitespace(true);
    DocumentBuilder builder = dbf.newDocumentBuilder();
    ByteArrayInputStream bais = new ByteArrayInputStream(XMLRetrievedData.getBytes());
    doc = builder.parse(bais);
    ANd then we can say :
    System.out.println( "getDocumentElement() was " + doc.getDocumentElement() );
    and we get the XML.
    If we run this in Tomcat the line
    System.out.println( "getDocumentElement() was " + doc.getDocumentElement() );
    produces
    [rft: null]
    instead of the XML we get when we run the same code in Eclipse !!
    We want to parse the DOM, delete some elements and add some new elements. Then we want to return the altered DOM as a String .. for whatever client needs it.
    Any ideas about this ? What could be wrong ?
    Thanks !!

    Beg pardon - I should have said we are loading the XML string shown into the String XMLRetrievedData. That's how the 'rft' part of the [rft: null] gets into Tomcat's output.
    Strange ...

  • Adding attachments to xml dom generated documents

    Hello All,
    I am trying to add an attachment to a DOM generated XML document, does anyone have any idea as to how I amy be able to do this.

    Hi
    Happen to see your posting. Did you get any response for your question. I have a similar requirement. If you have any pointers, please let me know. Thanks for your help in advance.
    Regards
    Sri

  • How to SAVE a updated XML DOM Data to the file?

    Hi
    I am able to load an XML file into a XML DOM object using JAVA (xerces). I have update the required data in the DOM.
    But I am NOT able to save back the data to the physical file.
    Will appreciate if you can help me ASAP.

    Hi Krishar,
    Check out the jaxp new release on java.sun.com. This api has classes and methods to help you do the same.
    sample code:
         try
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              java.net.URL url = this.getClass().getResource(XML_FILE);
              java.io.File thsFile = new java.io.File(url.getFile());
              DocumentBuilder builder = factory.newDocumentBuilder();
              TransformerFactory tFactory = TransformerFactory.newInstance();
              Transformer transformer = tFactory.newTransformer();
              document = builder.parse(thsFile);
    //You can do any modification to the document here
              DOMSource source = new DOMSource(document);
              StreamResult result = new StreamResult(thsFile);
              transformer.transform(source, result);
         catch (TransformerConfigurationException tce)
              System.out.println("\n** Transformer Factory error");
              System.out.println(" " + tce.getMessage());
              Throwable x = tce;
              if (tce.getException() != null)
                   x = tce.getException();
              x.printStackTrace();
         catch (TransformerException te)
              System.out.println("\n** Transformation error in add:");
              System.out.println(" " + te.getMessage());
              Throwable x = te;
              if (te.getException() != null)
                   x = te.getException();
              x.printStackTrace();
         catch (SAXException sxe)
              System.out.println("sax exp" + sxe.getMessage());
         catch (Exception ex)
              System.out.println("exc exp" + ex);
              ex.printStackTrace();
    Hope this will help you XML_FILE is constant representing the path of the file. It should be in classpath. The program essentially parsing a xml file and creating dom document and then writing it back to the same file. you can do any modifications/write to other file etc...
    Think this will suffice your requirement
    bye
    take care
    Hi
    I am able to load an XML file into a XML DOM object
    using JAVA (xerces). I have update the required data
    in the DOM.
    But I am NOT able to save back the data to the
    physical file.
    Will appreciate if you can help me ASAP.

  • BDB XML DOM Implementation

    Hi all---
    I have some newbie questions about BDB/XML's DOM Implementation and its interaction with Xerces-c.
    We are trying to deploy BDB/XML underneath our current database abstraction layer. The application makes use of Xerces-c and the abstraction layer query/get interfaces return objects of type Xercesc-XXXX::DOMDocument*. I can easily get documents out of BDB/XML and return the DOM to the upper layer by use of the XmlDocument::getContentAsDOM() interface.
    The problem occurs as the upper application layers start to manipulate the Document. For instance, in order to print the document, some code creates a serializer (DOMWriter) using Xerces-c, but when applied to the Document returned by BDB/XML the serializer corrupts the DOM and we get an ugly crash.
    I'm completely new to the intricacies/compatibility issues between DOM implementations---is what I am describing here supported in theory? Or is there a fundamental problem---some incompatibility between a Xerces-c DOMWriter and a BDB/XML DOMDocument?
    fwiw, the error appears to be caused by the Xerces-c memory manager which apparantly has no idea about pages being used by BDB, and is allocating structures on top of BDB objects.
    Any ideas? Advice where to investigate?
    thanks,
    SF

    Steve,
    First, the Xerces-C DOM implementation in BDB XML is not entirely complete, and is mostly read-only from an application perspective. So if you are doing anything to modify the returned DOM you run some risk. It's implemented using Xerces-C 2.7.
    Second, the availability of the Xerces-C DOM in BDB XML has a limited lifetime. It will almost certainly not be availble in the next release of BDB XML, so it's not something you should rely on. You may be best off serializing your results and if you want to manipulate them using Xerces, re-parse it into a DOM implementation that you control. I realize there is loss of efficiency in doing this.
    In our next release there are changes being made (for very good reasons) that make it impossible to maintain the XmlDocument::getContentAsDOM() interface. If we did keep it, we'd just be serializing and re-parsing anyway.
    Regards,
    George

  • XML - DOM tree - XML

    I'm building an application that takes an xml file, turns it into a DOM tree, then the user selects different options from a database to manipulate the internal information gathered by the original XML file, the program is a process and at the end of the process the original XML file has been updated with new information, i need help with finding some code to take the DOM tree information displayed to the user and save back out as a new XML file. any help would be greatly appreciated.

    You can use JDOM, Xerces XMLSerializer, or J2SE's Transformer. The first 2 are pretty simple. The 3rd isn't too hard. An example can be found in code sample 3 on http://java.sun.com/developer/technicalArticles/xml/JavaTechandXML_part3/.

Maybe you are looking for