How to modify a node value in a DOM tree?

I have following code; it parses a XML file from a file and builds a in-memory DOM tree, but when I tries to modify one of the node value, it keeps telling me: oracle.xml.parser.v2.XMLDOMException: Node cannot be modified. How do I do it?
// ==================================
DOMParser theParser = new DOMParser();
theParser.setValidationMode(false);
InputStream theInputStream = myApp.class.getResourceAsStream("/test.xml");
theParser.parse(theInputStream);
XMLDocument theXMLDoc = theParser.getDocument();
NodeList theNodeList = theXMLDoc.selectNodes("/root/child");
for (int i = 0; i < theNodeList.getLength(); i++)
theNodeList.item(i).setNodeValue("test");
null

You're trying to set the node value of an element, which cannot have a node value.
You need to set the node value of the text-node child of the element instead.
Or remove the current text-node child and append a new text-node child with the new value.

Similar Messages

  • How to get the node value of payload

    Hi
    The null is returned when I use the following code to get the User_ID element in the payload, but there are values in the User_ID element of the payload
    Task task_test = wfSvcClient.getTaskQueryService().getTaskDetailsById(wfCtx, taskId);
    System.out.println("the payload value is " + task_test.getPayloadAsElement().getElementsByTagName("User_ID").item(0).getNodeValue());
    How to get the node value of payload ? any suggestion?
    Thanks
    Jayson

    Hi Jayson,
    Try:
    System.out.println("the payload value is " + task_test.getPayloadAsElement().getElementsByTagName("User_ID").item(0).getFirstChild().getNodeValue());
    So add the getFirstChild() call in between.
    If this works, maybe consider using JAXB to marshall the payload details to POJO's. This will make reading the payload details much easier.
    Regards, Ronald

  • 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

  • Could someone help me out how to insert a Node properly into a DOM?

    I am trying to insert a Node built from a String to a DOM.
    Here is how I created the Node
                   Detail = "<Detail><Msg>Detail Message</Msg></Detail>";
                   prolog = "<?xml version="1.0" encoding="UTF-8"?>";
                   Node DetailNode = null;
                   Document DetailDoc = null;
                   if( Detail != null ){
                        Detail = prolog + BiometricDetail;
                        DetailDoc = xp.XML2DOM( BiometricDetail ); // transform a XML String into a DOM.
                        DetailNode = BiometricDetailDoc.getDocumentElement();                    
    Here is how I created the DOM
                   javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
                   javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
                   Document document = builder.newDocument();
                   Element beeE = document.createElement("BeeSets");
                   Element grpE = document.createElement("Group");          
                   bioE.appendChild( grpE );
                   // the document looks like "<BeeSets><Group></Group><BeeSets>";
                   // After inserting the Node DetailNode, I want it to look like
                   // "<BeeSets><Group><Detail><Msg>Detail Message</Msg></Detail></Group><BeeSets>";
    Now when I tried to insert the node DetailNode to the DOM document, I tried
    1) document.importNode( DetailNode, true );               
    No exception was thrown. But when I transformed the DOM document back to a String, I could not see the information from the newly imported Node DetailNode.
    When I tried
              grpE.insertBefore( BiometricDetailNode, dataE );
    I got the following exception.
         org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
         at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknown Source)
         at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
         at com.jadcs.bioidentity.role.base.RP.getNodes(RP.java:497)
    2) document.adoptNode( DetailNode );
    I got the following exception.
         java.lang.ClassCastException: org.apache.xerces.dom.DocumentImpl
         at org.apache.xerces.dom.DeferredTextImpl.synchronizeData(Unknown Source)
         at org.apache.xerces.dom.NodeImpl.setOwnerDocument(Unknown Source)
         at org.apache.xerces.dom.ParentNode.setOwnerDocument(Unknown Source)
         at org.apache.xerces.dom.ElementImpl.setOwnerDocument(Unknown Source)
         at org.apache.xerces.dom.ParentNode.setOwnerDocument(Unknown Source)
         at org.apache.xerces.dom.ElementImpl.setOwnerDocument(Unknown Source)
         at org.apache.xerces.dom.CoreDocumentImpl.adoptNode(Unknown Source)
         at com.jadcs.bioidentity.role.base.RP.getNodes(RP.java:509)
    3) detailStr = "<Detail><Msg>Detail Message</Msg></Detail>";
    Element detailE = document.createElement("Detail");
    detailE.setTextContent( detailStr );
    grpE.appendChild( detailE );
    This way gives result like "<BeeSets><Group><Detail><Detail><Flash>On</Flash></Detail></Detail></Group><BeeSets>";
    The content is messed up.
    Could someone help me out at how to insert a Node properly into a DOM? Thank you very much.

    Said another way, importNode actually only makes and returns a copy of the node you gave it (it will be a deep copy only if you pased true as the second parameter), but where the new dom you called import on is owner.
    So what you need to do is more like this:
    Node tempNode = domYouAreAddingTheNodeTo.importNode(node2copy,true); //true if you want a deep copy
    domYouAreAddingTheNodeTo.appendNode(tempNode);You can also traverse to any point in the DOM and insert the node there with the same method, but you always have to import first so that the DOM has a copy of the node that it owns.

  • How to get the Node Value from XmlValue result?

    Hi ,
    I am not able to get the Node Value from the result. In my XQuery im selecting till a Node, if i change my query as
    collection('PhoneBook')/phone_book/contact_person/address/string()", qc);
    im getting the node value, but here the problem is its not a Node so i cannot get the Node name.
    So how can i get the Node Name and Node value together?
    any help please ????
    XML :
    <?xml version="1.0" encoding="UTF-8"?>
    <phone_book>
    <contact_person>
    <name>
    <first_name>Michael</first_name>
    <second_name>Harrison</second_name>
    </name>
    <address city="yyyyy" pincode="600017" state="xxxxx">
    176 Ganesan street, Janakinagar, alwarthirunagar
    </address>
    </contact_person>
    <phone_number type="mobile">9881952233</phone_number>
    <phone_number type="home">044-24861311</phone_number>
    <phone_number type="office">080-12651174</phone_number>
    </phone_book>
    Code:
    XmlQueryContext qc = manager.createQueryContext();
    XmlResults rs = manager.query
    ("collection('PhoneBook')/phone_book/contact_person/address", qc);
    while(rs.hasNext()){
    XmlValue val = rs.next();
    System.out.println(val.getNodeName() + " = [ " + val.getNodeValue() + " ] ");
    Output
    address = [  ]

    You are right, this seemed un-intuitive to me too, but I finally understood how it's done.
    The "value" of a node is actually the total amount of text that is not contained in any of the node's child nodes (if any). So a node with child nodes can still have text value.
    To get the 'value' of an element node, you must therefore concatenate the values of all children of type "XmlValue::TEXT_NODE", of that node. Try it.
    In your example, the <address> node has no child elements, my guess is that BDB XML stores the address string "176 Ganesan street, Janakinagar, alwarthirunagar" inside a child node of <address> node (of type XmlValue::TEXT_NODE) because you wrote the string on a separate line.

  • How to edit the node value of a tree in webdynpro java

    Hi ALL
    I have Tree UI element where i got displayed all the nodes by calling the BAPI
    Now my requirement is when i put the cursor at any node in the Tree struture then on click of insert button i need to insert the new node with the text  , the user has to be option to give new text for the new node dynamically  , so while adding the new node in a tree the tree has to choose the text for new node , like how to edit the node of a tree to add new text.
    If any one can send the sample code on the same then it would be great help to me.
    Similar requirement like in table UI Like however we are adding the new row in a table when we click on the insert button then cursor will go to that new row in a table where user can enter his details in the table.. now i am looking for the same requirement in a Tree UI element.
    is it possible the same requirement in tree UI element in webdynpro for Java??
    Thanks
    kallki reddy

    Hi kallki reddy
    In general I think this is not possible in the form you'd like. It seems the Tree control is read-only thing always. It cannot provide editing capabilities.
    Table is different thing. You can select within many different cell editors including Input Fields.
    I guess that you scenario could be implemented not with Tree control, but with Table with Master Column. The master column allows to bring up a hierarchy into a plain table. So it's just a tree inside a table.
    Here you can find further details: [TreeByNestingTableColumn API|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/92/12a74046033913e10000000a155106/content.htm]
    BR, Siarhei

  • How to pass hierarchy node value to another report using RRI

    hi,
    i want to pass hierarchy node value to another report but i can not able to do this using hierarchy variable so i want solution for this.
    Reply me as soon as possible its very argent.

    Did you wanted to jump from Node to Node ? I guess you cannot do that....did you try ?

  • How to make all nodes in a detailed navigation tree open automatically??

    Dear All,
    I have added some iViews to two folders and add these two folders to a workset "Time" and then add "Time" to the role of Employee portal user.
    How to make all nodes expanded automatically when this workset is clicked in EP??
    thanks,
    Zita

    Not surprising...it does not work even if you follow the exact way...
    Role ->
             Workset 1
                          -> Page 1
                          -> Workset 2
                                           -> Page 2
                          -> Workset 3
                                           -> Page 3
    When the user clicks on Role which is the Entry Point, I want the user to see Page1 (works alright) and want the tree node Workset 2 open (doesn't work)...I want tree node Workset 3 closed (which is what happens...)
    The thing is Workset 2 has to be open...
    This is what I've done...I've made the Initial State of Navigation Panel set to "Open"...
    What else is to be done????
    Thanks a lot.
    JP

  • How to Modify Hierarchy Filed Values by using Import Manager

    Hi All,
    I have some lookup table values in my source file in 1st attempt I have updated successfully. But, after cross checks the same i found that hierarchy level are incorrect at the destination side.
    Source Hierarchy lookup values
    Item1
           Item 2
           Item 3
    Item4 
    Destination Hierarchy lookup values
    Item1
    Item 2
    Item 3
    Item4 
    Note: After Adding the Source filed hierarchy structure by selecting the  Add Branch as child opting in the value mapping area
    I am getting unique constraint Violated error message while importing the values.
    So, how can I update the Source Hierarchy fields structure to Destination Hierarchy Field structure?
    Thanks in Advance.
    Mahesh

    Hi Mahesh,
    While importing the values if you get the error unique constraint Violated, that means that the same value has been mapped twice.
    when you try to map the values of the hierarchy, NULL would have been automatically mapped.
    When you select all the records and do add branch as child, the same NULL would have been added and mapped again.
    If not with NULL, this could be the case with some other value.
    Just check if some value is added and mapped twice in your value mapping.
    This should solve your issue.
    Try and let me know the result.
    Regards,
    Sravan

  • How to modify an XML values using XSLT and Java

    Hi Friends,
    I wish to modify a simple xml to another xml using XSLT, please let me know what are the things i need to know to convert the XML to another XML.
    If somebody can give a sample code, it will be great...
    I wish to do the following sample conversion of XML
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <ROOT>
    <NAME>TEST1</NAME>
    </ROOT>so that the results look like below....
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <ROOT>
    <NAME>TEST2</NAME>
    </ROOT>Notice TEST1 is replaced with TEST2 in the 2nd XML, I wish to get that result...please help.
    Thanks and Regards,
    JG

    Thanks for your nice reply... do you have a sample code...

  • How to modify a static value to variable value

    how to change a static variable to no-static variable, the code you see is to validate an xml file, if I change this line
    private static final String XML = "xml/laPartieWord.xml";to
    String XML = "xml/laPartieWord.xml";I m getting error " Cannot make a static reference to the non-static field XML
    import java.io.*;
    import javax.xml.XMLConstants;
    import javax.xml.transform.sax.SAXSource;
    import javax.xml.validation.Schema;
    import javax.xml.validation.SchemaFactory;
    import javax.xml.validation.Validator;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    public class ValidationWXS {
    private static final String SCHEMA = "xml/laPartieWord.xsd";
    String XML = "xml/laPartieWord.xml";
    public static void main(String[] args) throws IOException, SAXException {
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema xsd = sf.newSchema(new File(SCHEMA));
    Validator validator = xsd.newValidator();
    SAXSource src = new SAXSource(new InputSource(XML));
    try {
    validator.validate(src);
    System.out.println("Le document '" + XML + "' est VALIDE!!!");
    } catch (SAXException e) {
    System.out.println("*** Le document '" + XML + "' n'est pas valide ***");
    e.printStackTrace();

    basics of java..
    private static final String SCHEMA = "xml/laPartieWord.xsd";
    String XML = "xml/laPartieWord.xml";
    put these inside main and remove the static of the first..
    shanu

  • How to select a node by name in a Tree?

    Hi,
    I require some help:
    I want to select a  Node of a Tree "myTree" by his displayed name.
    I can select a Node by using "myTree.selectedIndex = idx". But how do I get the current Index of that Node?
    Thx

    Hi there..
    I use a code like this..
    [Bindable] public var selectedNode:XML;
    [Bindable] public var mynewVar:String;
    public function treeChanged(event:ListEvent) : void   {  
    selectedNode = Tree(event.target).selectedItem as XML;
    mynewVar = selectedNode.@nameofNode;
    Cheers!

  • Setting Node value in a DOMtree

    Hello Techies,
    I am trying to create a DOM Tree. I had create Node's for the DOM Tree. I want to know how to set the Values to these Nodes.
    Element root = null;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();
    root = document.createElement(Root_Element);
    document.appendChild(root);
    Element applicationElement =document.createElement(Application_Element);
                applicationElement.setNodeValue("krish");
      root.appendChild(applicationElement);Now when I try to get the This Node Value , I am getting null Pointer Exception.
    Here is my code of retrieving the node value
    NodeList applicationNodeList = null;
    applicationNodeList =finalElement.getElementsByTagName("application");
    System.out.println("applicationNodeList size"+applicationNodeList.getLength());
          for(int i = 0; i<= applicationNodeList.getLength();i++)
               System.out.println("eachApplicaiton in the DOM"+applicationNodeList.item(i).getNodeValue());
               }I am getting NodeList size is 1 , but I the node Value I am getting as Null.
    What I am doing for setting the Node Value is correct(or) am I missing some thing.
    Can u guys help me out to fix this problem.
    regards,
    Krish.

    Thanx 4 u r reply.
    I had found where exactly the problem is .The element Node will take only null values.
    I have to create a DOM Tree in the following format.
        <Application>
            <application_id>   1 </application_id>
            <application_name>krish    </application_name>
            < description>   This is test </description>
      </Application>The values that I am placing in the following tags tage<application_id>,<application_name> and <description> are from database.
    My Code is
    Element root = null;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();
    root = document.createElement(Root_Element);
    document.appendChild(root);
    Element applicationElement =document.createElement(Application);
    root.appendChild(applicationElement);
    Element applicationIdElement =document.createElement(application_id);
    applicationIdElement.setNodeValue("1");
    appliationElement.appendChild(applicationElement);
    Now let us suppose that I had created Text Node
    TextNode t  =  applicationElement.createTextNode(application_id);
    applicationElement.appendChild(t);Now The value which I am getting from database I am not sure that it is always be a String , Some times , it may be
    int,bigInt,String,Clob.
    In this situation How can I create DOM Tree??
    To obtain the above xml structure, Whether I have to create text Node's under application?? Plz guide me.
    Looking forward 4 u r solutions
    Regards,
    Krish

  • Modify the preference value of the default route

    Hi
    How to achieve the Below ? any configuration example?
    1)How to modify the preference value of the default route to be less prefered than OSPF External route
    2)how to redistribute the default route as type 2 external route
    3)how to redistribute the default route as type 1 external route
    thanks

    Hi Ibrahim,
    See below:
    1) Can you elaborate on this a bit? Can you explain, specifically, what your trying to accomplish? I don't think you can get a default route into the OSPF RIB that is not external as the default is injected as a Type-5 LSA (e1 or e2). If your talking about getting a router to use the OSPF learned default over the default router learned via some other source (e.g. static, BGP, etc), then it depends on the source because of the Administrative Distance when comparing the two defaults ( the one default learned via OSPF has AD=110, and the other default is AD=X, where X is the Administrative Distance assigned to the protocol).
    2) Use the "default-information originate metric-type 2" command under "router ospf" -- Note this is the default
    3) Use the "default-information originate metric-type 1" command under "router ospf" -- Note, you don't need this in Totally Stubby Area.
    4) For NSSA area you have to use the "area nssa <area_num> default information-originate metric-type <type>" router subcommand. Note your NSSA should have a Type-7 LSA for the default route
    Rate if helpful.
    Joe

  • Xml: how to get node value when pasing node name as a parameter

    Hi,
    I've got some xml:
    var xmlData:XML =
    <1stNode>
        <buttonID>first child node value</buttonID>
        <imageID>second child node value</imageID>
        <labelID>third child node value</labelID>
    </1stNode>
    Then I want to read specific node value based on a value passed to a function. .
    var buttonID = new Button;
    var imageID = new Image;
    var labelID = new Label;
    getNodeValue(buttonID); //the value here is set dynamically
    private function getNodeValue (nodeName:String):void {
    trace (xmlData.nodeName)                      //doesn't work
    var str:String = "xmlData." + nodeName;
    var xml:XMLList = str as XMLList             //doesn't work
    I'm don't know how to get the value when node name is dynamically changed.

    use:
    getNodeValue(buttonID); //the value here is set dynamically
    private function getNodeValue (nodeName:String):void {
    trace (xmlData[nodeName])                    

Maybe you are looking for

  • Search metadata in Premiere that I create in Prelude

    So I am trying to get the video team more organized here where I work and Prelude seemed like a pretty awesome tool ... at first.  Call me crazy or maybe I am just completely missing this but when I ingest clips in Prelude and add custom metadata how

  • Runing procedures from DBMS_STATS package - how ?

    Hello, i created account long time ago, but this is first time i need help. How can i run this code with PHP, and get results. In sql+ works fine - i made some attempts without any good results. {sql} variable num_rows number; variable num_blks numbe

  • Firefox install causes error messages during startup and freezes during running

    I installed firefox 20 on Windows 7 and when I reboot I see several messages telling me that I am missing dll files. I have verified that all the dll files are in the install folder. I was able to run firefox without running firebug and just putting

  • After upgrading I lost all my events

    Not sure what's going on but I lost all my kids video's and more.  How can I get it back? Thank you.

  • Where can I find the multiple node block

    I am looking for the symbol that takes the negative and positive peakc and outputs one signal to measurement file: Figure 4. http://zone.ni.com/devzone/cda/tut/p/id/4644#toc1 Solved! Go to Solution.