Changing a Node in a DOM

Hi,
I was wondering if it is possible to Change a Node in a Document with a another node e.g. A Node is a copy, but has a different Value.
So effectively updating th Node and the Document.
Cheers,
IJ...

Do you need replaceChild?
     Node parent = node.getParentNode();
     parent.replaceChild(el, node);

Similar Messages

  • Changing Certain Node Icons

    I can't seem to figure out how to change certain node icons in a JTree due to a 3 letter string. For example 2 nodes one saying "Intro" the other say "Edit - SEC" - the one with SEC has a different icon to "Intro"
    MyRenderer class, here the code which is used to check the string of the node......
    if(leaf && isSecuredFile(value)) {
    setLeafIcon(leafSecuredIcon);
    setToolTipText("This file is Secured Access Only");
    else {
    setToolTipText(null);
    return this;
    protected boolean isSecuredFile(Object value) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
    NodeRecord nodeInfo = (NodeRecord)(node.getUserObject());
    String nodeTitle = nodeInfo.NodeRecord;
    if(nodeTitle.indexOf("SEC") >= 0) {
    return true;
    return false;
    }// MyRenderer class
    I tried the above piece of code, and it compiles with no errors but when I try to run the applet it comes up not initialised with the following....
    java.lang.NoClassDefFoundError: MyRenderer
    at firstPanel.<init>(firstPanel.java:99)
    at JNavigator.jInit(JNavigator.java:55)
    at JNavigator.init(JNavigator.java:40)
    at sun.applet.AppletPanel.run(AppletPanel.java:344)
    at java.lang.Thread.run(Thread.java:484)
    However if I take out this code it works fine but I need to be able to assign different icons depending on the node title string. Therefore I need help.

    here's the whole class, if thats any help...
    public class MyRenderer extends DefaultTreeCellRenderer {
    ImageIcon leafIcon;
    ImageIcon leafSecuredIcon;
    public MyRenderer() {
    leafIcon = new ImageIcon("Leaf.gif");
    leafSecuredIcon = new ImageIcon("LeafSecured.gif");
    public Component getTreeCellRendererComponent(JTree tree, Object val, boolean sel, boolean expand, boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, val, sel, expand, leaf, row, hasFocus);
    // sets Icons
    setLeafIcon(leafIcon);
    setClosedIcon(new ImageIcon("Folder95C.gif"));
    setOpenIcon(new ImageIcon("Folder95O.gif"));
    // set Expansion icons to + -
    ComponentUI treeUI = tree.getUI();
    if(treeUI instanceof BasicTreeUI) {
    ((BasicTreeUI)treeUI).setExpandedIcon(new ImageIcon("minus.gif"));
    ((BasicTreeUI)treeUI).setCollapsedIcon(new ImageIcon("plus.gif"));
    // decides who icon to use
    if(leaf && isSecuredFile(value)) {
    setLeafIcon(leafSecuredIcon);
    setToolTipText("This file is Secured Access Only");
    else {
    setToolTipText(null);
    return this;
    protected boolean isSecuredFile(Object value) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
    NodeRecord nodeInfo = (NodeRecord)(node.getUserObject());
    String nodeTitle = nodeInfo.NodeRecord;
    if(nodeTitle.indexOf("DOM") >= 0) {
    return true;
    return false;
    }

  • How to change the node's icon in a tree when the node collapse or expand?

    how to change the node's icon in a tree when the node collapse or expand?

    Hi,
    You may need to use custom skin for that.
    -Arun

  • Changing JTree node text results in "..."

    I'm working with a JTree, and I have a problem if I change the text displayed on a node. After changing the node, I call nodeChanged( node ) on the tree model.
    What happens is that if the new text on the node is longer than the previous one, the text is cut short and the end replaced by "...". E.g. if the old text was "foo" and the new is "foobar", it turns out as "foo...". This happens even if there is more than enough space in the tree to hold the complete new name, e.g other nodes in the same column with longer names.
    I guess somehow, the tree doesn't properly correct the layout of the cell to accomodate the longer text. I feel it is a bug, since I use the proper calls on the tree model to notify of the change.

    nodeStructureChanged() will give the exact same behavior.
    A solution is to use SwingUtilities.invokeLater().
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){model.nodeChanged(node);}
        });

  • How to append an xml string as a child node to a dom document

    Hi
    I have an xml represented as a String. Now I want to add this xml string as a child node to another DOM Document.
    Do I have to first parse the xml String into a xml Document and then add the nodes to the existing Document. Is there a simpler way to do this. Any input is appreciated.
    Many thanks in advance.

    radsat wrote:
    Hi
    I have an xml represented as a String. Now I want to add this xml string as a child node to another DOM Document.
    Do I have to first parse the xml String into a xml Document and then add the nodes to the existing Document. yes, this is what you need to do.
    Is there a simpler way to do this. Any input is appreciated.no, there really isn't, sorry.

  • Change SIA node name after restaure

    hi,
    we have backup an XI31 system (on server named AAA) and restaure it on another windows server ( named BBB).
    on CCM the SIA name is SIA.AAA
    on CMC the node for each server XI is AAA
    the pid for each server is AAA.server.pid
    how to change this node name ?
    recreate SIA ?
    thank's

    Hi
    you have two options:
    1) In the CCM create a new SIA with the default servers (use other CMS and SIA ports than the defaults) and point the CMS to the old repository. hen finished just remove the old SIA. Drawback: you have to reconfigure your server settings.
    2) Try to clone the old servers in the CMC (I assume you already have a CMS running on the new node) and when you through activate the new servers and remove the old ones. Do not forget to deactivate the old SIA in the CCM.
    Regards,
    Stratos

  • Change a node on a Cost Center Group

    Dear experts,
    Is there any way to change a node on a cost center group (KSH1) ? i also would like to change the description!
    Any tips?
    Thank you in advance..
    leandro.

    Click on the node and Click on the Wand Buttion  (Select:Shortcut F9)
    and there you can delete and change the place of the group. Dont think you can change text. For that you may have to create the node again.
    Thanks
    Naveen

  • Change the Node Color

    how do i change the Node color in the JTree

    What do you mean it doesn't help you? PhHein told you you need to use TreeCellRenderer and gave you a link to a tutorial, what more do you want? You need to create a class that implements TreeCellRenderer like:
    private static class CellRenderer implements TreeCellRendererAnd implement this method:
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
      boolean expanded, boolean leaf, int row, boolean hasFocus)If you want to be spoon fed, you need to pay for a tutor.

  • Change state nodes of af:menuTree by oher component ( h:commandButton )

    I have a page with <af:menuTree> and <h:commandButton> components.
    I want a action in a <h:commandButton for the <af:menuTree> back to the initial state (none expanded nodes).
    By other words, a action that changes the nodes states (to closed nodes), by other component (for example a <h:commandButton) .
    thanks,
    Sérgio Morais

    Hello
    I hope that JSF is made more robust in the future.
    I would like to extend UIData and create my own custom components and I would like that creating custom components would be easier. Now I am lost. Should I put all UIData TLD-attributes to custom extended UIData TLD-description or not and what else to do... Does attribute descriptions become inherited in TLD? Obviously not? It seems that there are not straight and honest 'how to' for extending JSF-components. At least I am so far out of luck with extending... and even in using custom attributes in custom renderer. Why to put attributes to tag and to component? I think I have seen this in some examples.
    And then there are properties. I have not yet learned what is the difference between attributes and properties... and when to use which... but I guess I have to learn this too.
    What comes to IFrames, I think that nothing MS IE -specifc should be put into JSF. Mozilla and Firefox etc. browsers are quite popular, especially in Java community. All ready made standard components of course would be welcome, and I am looking forward to get to extend them for customization.

  • How to change the nodes open hub destination objects?

    Hi,
    How one can change the nodes of open hub destination objects?
    As there was a need to change the nodes for certain open hubs i wonder how this could be acheived?

    well,
    I have open hub destination object saved under one node ( Yes that is Infoarea only )
    but now i notice that i need to save this open hub under different info area..
    so how can i change the infoarea of an open hub with out deleting and recreating it?

  • How can I change a Node owner?

    Hello
    I am using "org.w3c.dom.Document" to represent a structure which will be parsed to a XML file.
    When I am trying to move an Element from a Document to another I get this message:
    Exception in thread "AWT-EventQueue-0" org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
    How can I change the Element(Node) owner?
    Regards

    Document.adoptNode

  • Icon CHANGE in Node Renaming  for JTree

    HI all ,
    In JTree, V can rename a DefaultMutableTreeNode , by pressing F2 or triple click .
    By using the DefaultTreeCellRenderer ,
    I applied icons also by -- tree.setCellRenderer(myCellRenderer);
    But at the time of renaming , or when v press F2 ,
    the icon is changed to default settings ( leafIcon / openIcon / closedIcon ).
    How can I apply other Icons to nodes at the time of node renaming ?
    Please help ..
    Thanks

    MyTreeCellRenderer treeCellRenderer = new MyTreeCellRenderer();
    DefaultTreeCellEditor treeCellEditor = new MyTreeCellEditor(tree, treeCellRenderer);;
    MyTreeCellEditorListener cellEditorListener = new MyTreeCellEditorListener();
    treeModel = new DefaultTreeModel (rootNode);
    tree = new JTree(treeModel);
    treeCellEditor.addCellEditorListener(cellEditorListener);
    tree.setCellEditor(treeCellEditor);
    tree.setCellRenderer(treeCellRenderer);
    I am renaming the leaf nodes and MyTreeCellRenderer class override the method
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
    and set a different icon to the leaf nodes.
    And when i am renaming a leaf node , the default ( leafIcon ) icon will come only to the renaming node at the time of renaming . When i hit the enter key . the default leafIcon will disappear and my customised icon will come .........
    My question is that at the time of renaming ........ How v can getback the customised icon ?
    thanks

  • How to create a new DOM tree with nodes from another DOM tree?

    Hello,
    I would like to create a DOM tree by using nodes from an existing DOM. How can I do that? I tried with appendChild and it gaves me as error: "WRONG_DOCUMENT_ERR".
    Thx!

    The xml that should be parsed is something like that:
    <?xml version="1.0" encoding="UTF-8"?>
    <root xmlns="http://www.nebi.biz/schemas/bd/nebienvelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" BusinessDocumentVersion="7.0" xsi:schemaLocation="http://www.nebi.biz/schemas/bd/nebienvelope NeBiEnvelope_L_0_3.xsd">
        <Header>
            <To>
                <OrganisationId>OrganisationId0</OrganisationId>
                <DestinationType>DestinationType0</DestinationType>
                <Destination>Destination0</Destination>
            </To>
            <From>
                <OrganisationId>OrganisationId1</OrganisationId>
                <DestinationType>DestinationType1</DestinationType>
                <Destination>Destination1</Destination>
            </From>
            <Dialog>Dialog0</Dialog>
            <DialogId>DialogId0</DialogId>
            <MessageType>MessageType0</MessageType>
            <MessageId>MessageId0</MessageId>
            <Reference Role="buyer" Type="BusinessAgreement">Reference0</Reference>
            <SequenceId>SequenceId0</SequenceId>
            <Checksum Type="MD5">Checksum0</Checksum>
        </Header>
        <Body>
            <Order xmlns="http://www.nebi.biz/schemas/bd/order" BusinessDocumentVersion="7.0" OrderType="request" xsi:schemaLocation="http://www.nebi.biz/schemas/bd/order Order_L_0_96.xsd">
                <OrderId Role="buyer"/>
                <ProductLine Number="1">
                    <ProductUseCaseDetails Id="WICreation">
                        <wiCreation xmlns="http://mydomain.com/GRIPP/workitem">
                            <wiCreationHeader>
                                <userId>wmadm</userId>
                                <taskModelName>DNS02_CreateMasterZone</taskModelName>
                            </wiCreationHeader>
                            <wiCreationBody>
                                <DNS02CreationBody>
                                    <GlobalSection xmlns="http://mydomain.com/GRIPP/dns02">
                                        <Outcome>1</Outcome>
                                    </GlobalSection>
                                    <SpecificSection xmlns="http://mydomain.com/GRIPP/dns02">
                                        <Zonename>0.0</Zonename>
                                        <RRLocation>Domain</RRLocation>
                                        <RemoteSlaves type="multiline">
                                            <RemoteSlaveFQDN>test.com</RemoteSlaveFQDN>
                                            <RemoteSlaveIP>123.234.234.123</RemoteSlaveIP>
                                            <RemoteSlaveFQDN>test.net</RemoteSlaveFQDN>
                                            <RemoteSlaveIP>123.123.123.123</RemoteSlaveIP>
                                        </RemoteSlaves>
                                    </SpecificSection>
                                </DNS02CreationBody>
                            </wiCreationBody>
                        </wiCreation>
                    </ProductUseCaseDetails>
                </ProductLine>
             </Order>
        </Body>
        <Trace>
            <CheckPoint>
                <SystemName>SystemName0</SystemName>
                <SystemDateTime>2006-05-04T18:13:51.0Z</SystemDateTime>
            </CheckPoint>
        </Trace>
    </root>This is the output of the Document after parsing and augmentation with the Xerces parser.

  • Partial document/node retrieval with DOM

    I have constructed a DOMDocument of an XML input:
    - <email>
    - <folder name="inbox" id="">
    - <message id="54321">
    <time_received>2003-07-16 09:30:05</time_received>
    <sender>John St.</sender>
    <to> "aaa"</to>
    <to>"bbb"</to>
    <importance>High</importance>
    <subject>My subject</subject>
    <body>THis is great</body>
    </message>
    - <message id="12345">
    <time_received>2003-07-16 09:30:10</time_received>
    <sender>Tim Rice</sender>
    <to>"ccc"</to>
    <to>"ddd"</to>
    <subject>My subject 2</subject>
    <body>THis is great 2</body>
    </message>
    </folder>
    </email>
    I created a getter method which retrieve value using the tag, like
    get("to") returns "aaa", and another get("to") returns "bbb"
    I use getElementByTagName(...) to do this, but the problem is that
    another get("to") will return "ccc". As you can see for the XML file, this
    is not good because the "ccc" is within next "message" tag.
    I want to provide another method to let the user select within which "message"
    the getter method is functional.
    I seemed to me that I have to create some "partial" doc pointing to the sub-nodes.
    but I don't know how to do it, anyone has some idea about this?
    besides, XPath seems can deal with it , but I am not allow to use it...
    Thanks in advance!

    I'm not sure I follow, but I would consider creating your own objects that represent messages, and iterate through your xml/dom with xpath to build your objects. then get rid of the dom document and work with your collection of "message" objects. I just use DOM as as part of an adapter to convert xml data into the applications object model - abstract out the xml/dom dependencies from your app logic.

  • How to copy a node from one dom document to another?

    I have one dom document that I have to split up into multiple dom documents. I am able to get the inividual nodes that I want to put into seperate documents.
    My problem occurs when I create a new dom document and try to add the node from the parent document. I get an exception saying (copied from api: WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node. )
    How can I make it so that I can copy a node from one document and add it to another.

    Have you checked out the API called importNode in the DOM Document. It lets you move nodes between different documents.
    This api lets you simply copy the existing node from one document into another. without creating any new nodes for it.
    I have done a small example please have a look.
    Book.xml
    <?xml version="1.0"?>
    <books>
      <book>
        <name>Inside Corba</name>
      </book>
      <book>
        <name>Inside RMI</name>
      </book>
    </books>------------------------
    Book2.xml
    <?xml version="1.0"?>
    <books>
      <book>
        <name>Core Java </name>
      </book>
      <book>
        <name>Core JINI</name>
      </book>
    </books>-------------------
    MoveNode.java (copies nodes from doc2 into doc1)
    import java.io.*;
    import javax.xml.parsers.*;
    // structures
    import org.w3c.dom.*;
    import org.xml.sax.*;
    public class MoveNode
      public static void main(String[] args)
        // step1. create a factory and configure it
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        // step2. set various configurations
        factory.setValidating(false); // do not need validation at this time.
        factory.setIgnoringComments(false); // do not ignore comments
        factory.setIgnoringElementContentWhitespace(false); // do not ignore element content whitespace.
        factory.setCoalescing(false);
        factory.setExpandEntityReferences(true);
        // step 3 create a document builder
        DocumentBuilder builder = null;
        try
          builder = factory.newDocumentBuilder();
        catch(ParserConfigurationException e)
          e.printStackTrace();
        try
          Document doc1 = builder.parse(new File("book.xml"));
          Document doc2 = builder.parse(new File("book2.xml"));
          if (doc1 == null || doc2 == null)
            System.out.println("doc1 is null or doc2 is null");
            System.exit(1);
          } // if
          // fetch books from doc2
          NodeList list = doc2.getElementsByTagName("book");
          System.out.println("number of books found " + list.getLength());
          Node node1 = list.item(0);
          Node node2 = list.item(1);
          // get the root node of doc1
          Node root = (Node) doc1.getDocumentElement();
          root.appendChild(doc1.importNode(node1, false));
          root.appendChild(doc1.importNode(node2, false));
          //now doc1 should have 4 nodes
          System.out.println(doc1.getElementsByTagName("book").getLength());
        } // try
        catch(SAXException se)
          se.printStackTrace();
        catch(IOException ie)
          ie.printStackTrace();
    hope this helps.
    regards,
    Abhishek.

Maybe you are looking for