Casting a org.w3c.dom Node to a org.dom4j Node

Does anybody know how I can cast (convert) a w3c.dom Node to a dom4j Node?
If I just trying casting the w3c node "(org.dom4j.Node)" it throws an exception...

I have a org.w3c.dom.Node after calling HttpUnit's getDOMSubtree() method.
Now I would like to change that Node to an org.dom4j.Node so i can use dom4j's Node.valueOf() method on it.
Any idea how?

Similar Messages

  • Extends collection using generic type of org.w3c.dom.Element

    Hi, all.
    I am trying to extending collection using PriorityBlockingQueue.
    Extended queue is generic type of org.w3c.dom.Element.
    public class MyQueue<Element> extends PriorityBlockingQueue<Element> {***/}
    Compiler misunderstand to type of Element (as like E ?, not org.w3c.dom.Element), then methods in the code "this.peek ()" will be error reported by type difference.
    At fact, I tried it into MyQueue<Node> extends PriorityBlockingQueue<Node>, it not causes any misunderstanding.
    Is there any hack to indicates that the type is org.w3c.dom.Element ? This mean, MyQueue<org.w3c.dom.Element> extends PriorityBlockingQueue<org.w3c.dom.Element>...
    Thanks.

    public class MyQueue extends PriorityBlockingQueue<org.w3c.dom.Element>

  • Java.lang.ClassCastException: oracle.xml.parser.v2.XMLText cannot be cast to org.w3c.dom.Element

    Hello
    I am getting java.lang.ClassCastException: oracle.xml.parser.v2.XMLText cannot be cast to org.w3c.dom.Element error. This code is in java which is present in java embedding.
    The SOA is parsing the xml in java code using oracle.xml.parser.v2 . This wont be a problem if the SOA uses default w3c DOM parser. How do i force SOA to use w3c DOM parser.
    Is there any thing i can do with class loading?
    Kindly help.
    Regards
    Sharat

    Can you paste your java code here ? I assume, you must have tried type-casting.

  • Set Name of org.w3c.dom.Node (= chang the TagNam)

    Hi all,
    How I can set name of my object org.w3c.dom.Node.
    In fact, this is an Element and I want to chang the tag <label> to <LABEL> befort write out DOM to XML File
    thanks a lot
    dseaa

    org.w3c.dom.Element interface does not have a setTagName() method.
    Implement interface org/w3c/dom/contentModel/CMElementDeclaration which has a setTagName() method.
    http://www.w3.org/TR/2001/WD-DOM-Level-3-CMLS-20010419/java-binding.html

  • Problem of using "org.w3c.dom.Node" class

    I try to use removeChild(child) method of "org.w3c.dom.Node" object. it don't work.
    is it better to do child=null;

    child=null does nothing to the dom object
    removeChild works fine. You're just confused.
    You would need more info to have any chance of fixing the problem.

  • Cost of creating org.w3c.dom.Node

    I am trying to create an xml of cached data at run time. I need to know if this would increase the response time considerably ..?
    Is there any documents which talk about the cost of creating nodes(e.g.within loops) ..?
    public Node createnode(Document d, String node_name, int node_value) {
    org.w3c.dom.Node temp_element_node, temp_text_node;
    temp_element_node = d.createElement(node_name);
    temp_text_node = d.createTextNode(node_name);
    temp_text_node.setNodeValue(node_value + "");
    temp_element_node.appendChild(temp_text_node);
    return temp_element_node;
    Has anybody implimented a pool of nodes(like pool of database connections). Any information is appreciated!

    It would certainly depend somewhat on which parser you were using, but i can't imagine it would be any more costly than any other type of object.

  • Adding org.w3c.dom.Node

    Hi,
    can someone please tell me if it is posible do read a org.w3c.dom.Node from one XML file, and than add it to another? Or is there a way to copy one org.w3c.dom.Node to another XML?
    Thanx,
    Alan.

    Refer to
    http://javaalmanac.com/egs/org.w3c.dom/CloneSubtree2.html

  • How to initialize a org.w3c.dom.Node object?

    Hello,
    I want to initialize an org.w3c.dom.Node object with an empty Node.
    How could I do that?
    Thanks
    Sylvain

    I want to create a Document.
    If I test your line, this error appears:
    "Default constructor cannot handle exception type javax.xml.parsers.ParserConfigurationException thrown by implicit super constructor. Must define an explicit constructor."
    Do you know what's happen?
    Thanks
    Sylvain

  • Problem casting org.w3c.dom.Document to oracle.xml.parser.v2.XMLDocument

    I have the following problem:
    I get my xml-documents as an XMLType from the database and want to compare these using the supplied Oracle class oracle.xml.differ.XMLDiff (i use the java version supplied with Oracle 9i r2).
    XMLType.getDOM() returns the xml-document as a org.w3c.dom.Document,
    what i need for oracle.xml.differ.XMLDiff is a oracle.xml.parser.v2.XMLDocument.
    How can i cast/convert between these two formats?
    thanks!
    p.s. cross-posting with Re: Casting/Converting XMLType to XMLDocument? (but i think this forum is more relevant).

    Hi,
    thanks for the suggestion: i have written the code shown below. It results in a casting error.
    As far as i know, i don't use a oracle.xdb.dom.XDBDocument, i only use a oracle.xdb.XMLType as the input parameter for my conversion-method:
    any new suggestions ???
    p.s. the second method which is commented does work, but is a bit verbose.
       private static oracle.xml.parser.v2.XMLDocument convert2XMLDocument(XMLType xml) {
         // simple version (should work according to tech. doc. 9i r2/ 10g r1 database)
         oracle.xml.parser.v2.XMLDocument doc = null;
         try {
            // n.b. probleem is dat XMLType.getDOM() een w3c.Document object teruggeeft ipv een oracle.XMLDocument.
            System.out.println("convert2XMLDocument(): casting w3c.Document naar oracle.XMLDocument.");
            doc = (oracle.xml.parser.v2.XMLDocument) xml.getDOM(); // public org.w3c.dom.Document getDOM()
            System.out.println("convert2XMLDocument(): done casting w3c.Document naar oracle.XMLDocument.");
         catch (Exception e) {
            e.printStackTrace(System.out);
        return doc;
       private static XMLDocument convert2XMLDocument(XMLType xml) {
         // complex version: works ok !!!
         XMLDocument doc = null;
         try{
            DOMParser parser  = new DOMParser();
            parser.setValidationMode(oracle.xml.parser.v2.XMLParser.NONVALIDATING);
            parser.setPreserveWhitespace (true);   
            parser.parse(new StringReader(xml.getStringVal()));
            doc = parser.getDocument();
        catch ( XMLParseException e ) {
          e.printStackTrace(System.out);
        catch ( SQLException e ) {
          e.printStackTrace(System.out);
        catch ( Exception e ) {
          e.printStackTrace(System.out);
        return doc;
    convert2XMLDocument(): casting w3c.Document naar oracle.XMLDocument.
        java.lang.ClassCastException: oracle.xdb.dom.XDBDocument
         at pnb.bdb.xml.testJDBC.convert2XMLDocument(testJDBC.java:305)
         at pnb.bdb.xml.testJDBC.main(testJDBC.java:187)

  • How to convert SOAPEnvelope or SOAPBody to org.w3c.dom.Node and vice versa?

    How to convert javax.xml.soap.SOAPEnvelope or javax.xml.soapSOAPBody to org.w3c.dom.Node and vice versa?If this convertion is very diffcult , how to convert String to org.w3c.dom.Node?
    Thanks a lot

    vj008 wrote:
    while parsing a DOM i want to convert
    org.w3c.dom.Element to xml string and after certain processing on that xml string i want to convert back it to
    org.w3c.dom.Element.[This might help. xml transformations in java. |http://tejaspurohit.blogspot.com/2009/08/xml-transformations-in-java.html]

  • How to add node value using org.w3c.dom.Document?

    Hi ,
    I'm using org.w3c.dom.Document to deal with xml files. I could successfully add nodes , and their attributes. However I could not add a value of the node. (e.g. <myNode>I couldn't add this value</myNode>)
    does anyone know how to deal with this?
    I tried subNode.setNodeValue("the value i can't add"); whereas the subNode is an instance of org.w3c.dom.Node... i know this is interface i of course used the concrete class
    org.apache.crimson.tree.ElementNode
    but when I used the subNode.getNodeValue() i simply got null?
    can u plz help me?
    thanks in advance

    Reading the API documentation for the Node interface might help. At least you wouldn't be surprised when the results are exactly what the documentation says they will be.
    What would really help would be forgetting the idea that an Element can have a value. Text nodes have values, though, so create a Text node and make it the child of the Element node.

  • NoSuchMethodError with org.w3c.dom.Node.getTextNode()

    Hi,
    I got a trouble with this method. I developped my app with Eclipse and jdk 1.5.
    I used the endrosed mechanism for updating xalan and xerces in my jre.
    Everything works fine on my computer, but as I want to run my app on an other machine, I got this error.
    I put a copy of my jre on the other machine and I launch the app from this jre. It seems the endorsed jars are taken in account, but it still doesn't work.
    Thanks for your help.

    I found ths solution.
    In my jre was missing the endorsed Dom.jar, found at jaxp.dev.java.net. to overwrite org.w3c.dom standard classes.

  • Org.w3c.dom.Element to javax.xml.soap.SOAPElement

    I have a org.w3c.dom.Element that I want to insert into an existing SOAPBody using
    public SOAPElement addChildElement(SOAPElement element). How can I turn the org.w3c.dom.Element
    into a javax.xml.soap.SOAPElement so that I can do that?
    Steve Watson

    Hi Steve,
    Here's a code segment that may be of some value.
    Bruce
         public SOAPElement populateSOAPElement(SOAPEnvelope envelope,
    SOAPElement element, Element sndElement) throws SOAPException{
    int i, j;
    NamedNodeMap map;
    Node node;
    NodeList list;
    SOAPElement subElement;
    //populate attributes
    map = sndElement.getAttributes();
    for (j = 0; j < map.getLength(); j ++)
    node = map.item(j);
    element.addAttribute(envelope.createName(node.getNodeName()),
    sndElement.getAttribute(node.getNodeName()));
    //populate the element value and subElements
    list = sndElement.getChildNodes();
    for (j = 0; j < list.getLength(); j ++)
    short type = list.item(j).getNodeType();
    String typeString = "";
    if (list.item(j).getNodeType() == 3)
    element.addTextNode(list.item(j).getNodeValue());
    if(list.item(j).getNodeType() == 1)
    subElement =
    element.addChildElement(((Element)list.item(j)).getTagName());
    subElement = populateSOAPElement(envelope, subElement,
    (Element)list.item(j));
    return element;
    Steve wrote:
    >
    I have a org.w3c.dom.Element that I want to insert into an existing SOAPBody using
    public SOAPElement addChildElement(SOAPElement element). How can I turn the org.w3c.dom.Element
    into a javax.xml.soap.SOAPElement so that I can do that?
    Steve Watson

  • Help: program error: package org.w3c.dom does not exist

    i 've already downloaded and unpacked the java-xml-pack by following the given instruction. again when i compile the program, the compiler still can't locate the package.. org.w3c.dom where i've already import org.w3c.dom.* at the beginning of the program. so, until now, the symbol like Document, Node still can't be resolved.
    is there any important step that i've missed ??

    Even I have faced the same problem, the Reasons can be:
    1. Take the latest packages of all the JAR files U need for XML Parsing.
    2. Set the class path for all the JAR files.
    2nd thing should be the reason for U getting the error.
    All The Best.

  • Validate org.w3c.dom.Element against xsd

    I need to validate a org.w3c.dom.Element against an xsd.
    DOMParser dp = new DOMParser();
    URL xmlurl = new URL("file:\\test.xml");
    XSDBuilder builder = new XSDBuilder();
    URL xsdurl = new URL("file:\\test.xsd");
    XMLSchema schemadoc = (XMLSchema)builder.build(xsdurl);
    dp.setXMLSchema(schemadoc);
    dp.setValidationMode(XMLParser.SCHEMA_LAX_VALIDATION);
    dp.setPreserveWhitespace(true);
    dp.setErrorStream (System.out);
    System.out.println("Parsing "+xmlurl);
    dp.parse(xmlurl);
    This works when my input is an xml file. I cannot get it work against an element. If I convert the element as a string or inputsource it gives the error
    "XML-20220: (Fatal Error) Invalid InputSource.
    java.net.MalformedURLException: no protocol:"
    Any idea how it can be done? I am using jdeveloper 10.1.2
    Thanks
    MM

    Thanks for the reply. I get the following error.
    Exception in thread main
    oracle.xml.parser.v2.XMLDOMException: cannot add a node belonging to a different document
    at oracle.xml.parser.v2.XMLNSNode.checkNodePermissions(XMLNSNode.java:854)
    at oracle.xml.parser.v2.XMLNSNode.appendChild(XMLNSNode.java:257)
    at oracle.xml.parser.v2.XMLDocument.appendChild(XMLDocument.java:1010)
    at test.parser.ParseTest.parse1(ParseTest.java:136)
    at test.parser.ParseTest.main(ParseTest.java:63)
    Process exited with exit code 1.
    This is my code
    public void parse1(Element elem) {
    try{
    //Element docElement;
    //Node elemNode=(Node)docElement;
    DOMParser dp1 = new DOMParser();
    XMLDocument xmlDocument=new XMLDocument();
    xmlDocument.appendChild(elem);
    ByteArrayOutputStream docOutputStream = new ByteArrayOutputStream();
    xmlDocument.print(docOutputStream);
    ByteArrayInputStream docInputStream = new ByteArrayInputStream(docOutputStream.toByteArray());
    InputSource inputSource = new InputSource(docInputStream);
    dp1.parse(inputSource);
    catch (IOException e){e.printStackTrace();}
    catch (XMLParseException e){e.printStackTrace();}
    catch (SAXException e){e.printStackTrace();}
    Thanks
    MM

Maybe you are looking for

  • Front Row on an External Display

    **Note that this is for Leopard's Front Row and only may not apply to Tiger's** Here's an explanation of the bugs/irksomes now facing Front Row 1. The screensaver option can be buggy so go to preferences within Front Row to disable it. 2. Whatever sc

  • Images show up only as blue question marks

    I just purchased a new Macbook Pro approximately one week ago, and concitering it's BRAND NEW I don't understand why I have this problem. On sites like www.deviantart.com and also www.weheartit.com images show up as blue question marks... I have down

  • Best Scenarios when to use IDOC Adapter, RFC Adapter and Proxy

    Please provide me links/weblogs which demonstrate the full scenario that when to use IDOC Adapter, RFC Adapter and Proxy when working with sender R/3 system. Regards Rachit

  • [HELP] Can WLS 8.1 run on JRE (instead of JDK)?

    Hello everybody, I dimly remember reading not long ago that WLS must be run from JDK's java not JRE's for full functionality, but now I can not find that explicitily stated anywhere. Platform is WLS 8.1 sp2 on solaris 8, .sh installer (full version w

  • Lumia 800 feature suggestions

    Here is my take of what Nokia Lumia 800 is missing. My previous BlackBerry Curvey was able to switch itself off at a pre-set time in the evening, to wake up again in the morning. This partly contributed to its 3-4 -day battery life. Nokia (Windows) s