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.

Similar Messages

  • Could someone help me out? ActionScript

    import flash.display.MovieClip;
    var clip:clip01 = new clip01;
    var clip2:clip02 = new clip02;
    var clip3:clip03 = new clip03;
    var clip4:clip04 = new clip04;
    var clip5:clip05 = new clip05;
    var files:Array = [clip,clip2,clip3,clip4,clip5];
    function randomizeArray(array:Array):Array
        var newArray:Array = new Array();
        while (array.length > 0)
    newArray.push(array.splice(Math.floor(Math.random()*array.length), 1));
        return newArray;
    var RandomArray:Array = randomizeArray(files);
    trace(RandomArray[0]);
    trace(clip);
    var c:MovieClip = MovieClip(RandomArray[0]);
    addChild(clip); // it’s OK
    addChild(c); // I get the error msg bellow:
    Scene 1, Layer 'movies', Frame 1, Line 29              1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.
    Could someone help me out?
    I cannot add MovieClip on the stage from the array.

    I have done till this the following code bellow. I’d like movie clip on the
    stage to be playing one after another in a randomized order in a loop. I
    used a timer, but this solution is not good, because the movies are not
    playing till the end. I need an EventListener to listen the end of the clip.
    How this code could be modified to work well, could you give me a solution
    to this problem?
    import flash.display.MovieClip;
    var clip1:clip01 = new clip01  ;
    var clip2:clip02 = new clip02  ;
    var clip3:clip03 = new clip03  ;
    var clip4:clip04 = new clip04  ;
    var clip5:clip05 = new clip05  ;
    var files:Array = new Array();
    pushArray(clip1,clip2,clip3,clip4,clip5);
    function pushArray(c1,c2,c3,c4,c5:MovieClip){
                    files.push(c1);
                    files.push(c2);
                    files.push(c3);
                    files.push(c4);
                    files.push(c5);
    function randomizeArray(array:Array):Array
                    var newArray:Array = new Array();
                    while (array.length > 0)
                                    newArray.push(array.splice(Math.floor
                                    (Math.random()*array.length), 1)[0]);
                    return newArray;
    var RandomArray:Array = randomizeArray(files);
    var testTimer:Timer = new Timer(1000);
    testTimer.addEventListener(TimerEvent.TIMER,updateFile);
    testTimer.start();
    function updateFile(event:TimerEvent):void
                    if (RandomArray.length == 0)
                                    pushArray(clip1,clip2,clip3,clip4,clip5);
                                    RandomArray = randomizeArray(files);
                    trace('play file',RandomArray[0]);
                    RandomArray.shift();
    //RandomArray[0].addEventListener(Event.ENTER_FRAME, VideoFinished);
    function VideoFinished(e:Event):void {
         if (RandomArray[0].currentFrame==RandomArray[0].totalFrames) {
              trace("finished");
    //addChild(RandomArray[0]);

  • Hi im having trouble with downloading an album off my computer. i have forgotten the security questions, but have already sent them to my email. could someone help me in how to get the answers?

    Hi im having trouble with downloading an album off my computer. i have forgotten the security questions, but have already sent them to my email. could someone help me in how to get the answers?

    Hello Carpets,
    Thanks for the question. You can reset your security questions with your rescue email address, as outlined with this article:
    Apple ID: All about Apple ID security questions
    http://support.apple.com/kb/HT5665
    If you do not see the option for resetting your questions with a rescue email address, see this excerpt:
    Note: The option to send an email to reset your security questions and answers will not be available if a rescue email address is not provided. You will need to contact iTunes Store support in order to do so.
    Rescue email address and how to reset Apple ID security questions
    http://support.apple.com/kb/HT5312
    Additional Information:
    Apple ID: Contacting Apple for help with Apple ID account security
    http://support.apple.com/kb/HT5699
    Thanks,
    Matt M.

  • My iPod doesn't seem like enjoy working, could someone help me out?

    This is my second iPod (I had to send the first one back to get it replaced) and it's getting ridiculous. About three months ago it stopped working again (the new one) and I got a box to send it back, but I tried installing new software and updating it and all, which fixed it, or so I thought. Now it's not working again. I can't even get it connected to my computer without the computer freezing completely. iTunes refuses to load when the iPod is connected, and "My Computer" (I have a win laptop) quits responding when I connect it too. If I could get it connected I would reset it completely, which I don't midn doing, but it doesn't seem to be able to do that. Has anyone else had this problem? I'd really appreciate help with this problem because Apple says I can't send it back... even though it's my second one. Any help would be appreciated greatly. Thanks in advance.
    -FF
    the ipod was bought for christmas last year (04), and is a click wheel, but not a color photo, or vid ipod.

    This is my second iPod (I had to send the first one back to get it replaced) and it's getting ridiculous. About three months ago it stopped working again (the new one) and I got a box to send it back, but I tried installing new software and updating it and all, which fixed it, or so I thought. Now it's not working again. I can't even get it connected to my computer without the computer freezing completely. iTunes refuses to load when the iPod is connected, and "My Computer" (I have a win laptop) quits responding when I connect it too. If I could get it connected I would reset it completely, which I don't midn doing, but it doesn't seem to be able to do that. Has anyone else had this problem? I'd really appreciate help with this problem because Apple says I can't send it back... even though it's my second one. Any help would be appreciated greatly. Thanks in advance.
    -FF
    the ipod was bought for christmas last year (04), and is a click wheel, but not a color photo, or vid ipod.

  • Could someone help me out, and kinda give me a walk through.

    I have a video in quicktime format, and everytime ive converted it to MPG4, the audio is early and the video is late. So my question is, how do i fix this?

    did you try using this software.it might prove better in converting.
    To use Videora iPod Convertor to convert movies for use on your iPod, consult these helpful links:
    To get started: http://www.videora.com/en-us/Converter/iPod/
    If you have questions: http://www.videora.com/en-us/Converter/guides.html
    If you have more questions, post them here: http://www.pspvideo9.com/forums/index.php?c=8
    Note that Videora iPod Convertor is a 3rd party program. If you need help with it, post your question there.
    GFF

  • Could someone help me out?

    Hi,everybody:
    I don't familiar with Solaris and OAS any more,in fact I'm a freshman in this field.But recently I've done a JAVA project and its enviroment is Solaris 5.7 and OAS R.4.0.8.2.
    I wanna ask you some questions if not bother you:
    1: Can OAS be used as Application Server and Http Server simultaniously?
    2.How to set the Http Listener in Solaris?
    3.Has OAS any administrator functions like IIS site management? And how to get it shown?
    4.How can we get a detailed OAS manual and a Solaris Operating manual?I can't find a suitable one from the site?
    Ah... Too many questions,really sorry to take your time,but I'm really in a hurry.In my experience,I often use Windows but not Linux or Solaris,and use VB,ASP but not JAVA.So I am a beginner here and the question maybe too easy to you.^_^
    Waiting your help.Thanks

    Wei,
    A forum is not the place to learn new technologies. If you are new to
    Oracle and java, then you are going to have to either do some serious
    reading or attend some courses (or both). You have abundant resources
    available to you, but if you are serious about becoming proficient in
    these technologies, then there is only one way to do it -- investing
    time and effort in learning them. As I said before, in order to learn
    them, you need to read, attend courses and practice.
    In my opinion, the task of the forum is to supply specific answers for
    specific questions (like,'what JAR file do I need to add to my CLASSPATH?')
    and not,'please provide a step-by-step tutorial on how to create,
    deploy and execute a web-based J2EE application using Oracle and
    JBuilder'.
    If you want help locating appropriate resources, I can offer you
    suggestions (like those I mentioned in an earlier post).
    Good Luck,
    Avi.

  • Did somebody find out how to insert citations from Papers into a document of Pages 5.1?

    Apparently Apple has sacrificed Apple Script in the new version, which is required for these kind of functionality.
    I really loved Pages '09 for its stability, functionality and ease of use. I also do like the new look of Pages but unfortunately this is not what matters for professional use.
    Can't use Papers 5.1 like this :-(
    Best

    Pages '09 should still be in your Applications/iWork folder.
    What do you like in the "new look"?
    Peter

  • I would like to change the owners name on my ipad2 to my daughters name and credit. Could someone help me figure this out?

    I would like to change the owners name on my ipad2 to my daughters name and credit. Could someone help me figure this out?

    Sign out from Find My Phone in iCloud, and sign out from your Apple ID in Settings/iTunes & App Store
    Then setup as a new phone with iTunes and when your Daughter sets it up for the first time she can add or set up her own Apple ID.
    Cheers
    Pete

  • HT4623 i have updated my iphone to ios 6.0.1 but it is not activating so please could you help me out....while inserting in itunes it showing no sim card inserted

    i have updated my iphone to ios 6.0.1 but it is not activating so please could you help me out....while inserting in itunes it showing no sim card inserted

    All iPhones sold in Japan are carrier locked. The Japanese carriers do not offer unlocking.
    You can not use that phone on a carrier other than the one it is locked to.
    Sell it and buy one you can use.

  • HT201320 My phone was stealed, how could i find it back? could someone help me? thanks in advance

    My phone was stealed, how could i find it back? could someone help me? thanks in advance

    Report lost or stolen Apple product
    http://support.apple.com/kb/HT2526
    Be sure to read the  Additional Information Section.

  • Could someone help me and telling me how I do a copy from one song. don't tell me press the button copy - doesn't work anymore!!!

    could someone help me and telling me how I do a copy from one song. don't tell me press the button copy - doesn't work anymore!!!???

    i made a "playlist" and did some aac-version, because i need the songs for different length of time. but some of this songs i need the same way (i teaching aqua gym lessons). and earlier i could made a copy and past and it worked. but now, nothing worked! everytime something is different.
    sorry, actually i am not so good in english to explain my problems i prefere german.

  • I have a Mac mini Snow Leopard. In Numbers the grid lines are so faint that they are barely visible. Please could someone help me sort out this problem.

    I have a Mac mini Snow Leopard. In Numbers the grid lines are so faint that they are barely visible. Pleease could someone help me sort out this problem?

    The User Manual has this:
    Formatting Table Cell Borders
    You can change the line thickness and color of table cell borders. Or you can hide the border of any cell.
    To format table cell borders:
    1 Select the cell border segments you want to format.
    2 Use the controls in the format bar or in the Table inspector.
    Click to choose a stroke color.
    Click to choose a stroke style.
    Click to choose a line thickness.
    Stroke pop-up menu:  Lets you choose a stroke style. Choose None to hide borders.
    Line thickness:  Controls the thickness of the stroke.
    Color well:  Lets you choose a stroke color.
    When you click the color well in the format bar, a color matrix appears. Select a color by clicking it in the matrix, or click Show Colors to open the Colors window for additional color options.
    When you click the color well in the Table inspector, the Colors window opens.
    User Guide: http://manuals.info.apple.com/en_US/Numbers09_UserGuide.pdf

  • HT5557 Using IBook, I can't seem to figure out how to insert a blank page inbetween pages that are already set up, like if you want to add some pictures or something.  Anyone have any tips on this?  Thanks, Mark

    Using IBook, I can't seem to figure out how to insert a blank page inbetween pages that are already set up, like if you want to add some pictures or something.  Anyone have any tips on this?  Thanks, Mark

    To enable the form to be signed in Reader you will need to open the form in Acrobat; goto Advanced>Enable Usage Rights and then save this copy of the form for sending out to the users.
    The user should then be able to edit and digitally sign the form. They can then email the signed/saved pdf as a browsed for attachment or via the email icon in the toolbar. Note - if you have created an email submit button on the form, then unless they have Acrobat they could only return an xml file.
    The other way to do this however is to create a dataset by 'distributing' the form. This time the Email Return button will send back a full version of the form. During the distribution setup you will have the option to email the form directly or to save it and send it later,so you can send to users as and when or even post it to a website or intranet.
    When you receive and open the returned form it will ask whether you want to add it to the predetermined dataset (or if you want to categorise the returns into geographical areas for example, you could create new additional datasets at this point). If the form is data heavy however, the dataset will become very large and unwieldy pretty quickly, but you can export the data from it (including signatures) in xml format and import this into an Excel spreadsheet.
    To simplify the Excel xml import process I'd recommend you carefully structure your form in the hierarchy (LiveCycle) into the order you would want the data items to appear in your spreadsheet and switch off those data items that you will not need by setting the default binding for the irrelevant fields to "None".
    Clear as mud? Hope this helps.

  • Am new at pages and cannot figure out how to insert a bullet where I want it in the text, not at the beginning of the paragraph.  Word was much easier for me

    Am new at this forum and also at pages and can't figure out how to insert a bullet where I want it in the text, not at the beginning of the paragraph.  I found word much easier to use.  Please help. Trying to do a resume.

    On a US keyboard it is Option + 8 (above the letters). •

  • Could someone please sketch out this simple script for me?

    Could someone please sketch out a simple java script for me. I will have a document with one background
    layer and a layer set (group) called "Analyze" that consists of 63 adjustment layers. The layer names in that "Analyze" group(folder) will be
    "01" ...through "63" with 01 on the bottom and 63 at the top. Initially, all of the adjustment layers will be invisible and  the
    group will be closed (not expanded). I need a simple  script that will check for the first invisible layer in that group
    and make it visible without selecting that layer nor expanding the group. The script has to check
    for the first invisible layer every time it runs because other actions may have turned off a layer in the set.
    The point of this is so I can hotkey flipping on the layers one at a time without expanding the set or
    changing focus off the  background. It seems it should be a simple loop, but I just can't wrap  my head
    around all the objects (e.g. Layer as opposed to Layers  and  Artlayer as opposed to Artlayers)
    and the constants constants.
    for (i = 63; i>0; i--){                 /* I have found layer indexes 0 are the topmost layer */
      if( layerset[i] == INVISIBLE){
               layerset[i] = VISIBLE;
                  break;
    Could someone please write me a simple script that would do this?
    Edit I found this and its very close to what I need:
    var doc = app.activeDocument;
    for(var i = 0 ; i < doc.layers.length;i++){
      doc.layers[i].visible = (i % 2 == 0);
    From here : Function to show/hide layer with Photoshop script (JSX) - Stack Overflow
    In my case I would rewrite it to this
    for(var i = 62; i >=0; i--){
         if(  !doc.layers[i].visible){
              doc.layers[i].visible =TRUE;
              break;
    My problem is I just need  to traverse the layers in my layerset "Analyze"
    How do  I reference just those? Is there a doc.layersets["Analyze"].layers[i].visible = TRUE?
    Message was edited by: Shawn Laughlin To add more information

    Well this works:
    var doc = app.activeDocument;
    var analyze = doc.layerSets.getByName("Analyze").layers
    for(var i = 62 ; i >= 0; i --){
        if (!analyze[i].visible){
            analyze[i].visible =1;
            break;
    Hard to believe TRUE is not a constant in java.

Maybe you are looking for

  • ITunes Library been deleted, how do I want save what I have on my ITouch?

    Hi, I have recently been made redundant but they let me keep my work laptop, which has my ITunes on it. However, the IT staff deleted a lot of things before handing it back to me, including my entire ITunes library. I have looked into similar questio

  • Wl6.0 clustering error

              Hi,           I have two weblogic servers on different m/cs in a cluster.When the request is going           to one server it is showing the following error.What could be the reason?           weblogic.cluster.replication.NotFoundException:

  • Automatic reversal of WIP

    Hi all my client wants that the system should automatically reverse the previously calculated WIP after final confirmation of order.Is it possible? if yes what is procedure?(with out useing KKAX &KO88) urgent pl Regards Sankaram

  • HT3204 secure link to itunes store failed duing ituses diagnostics, trouble downloading any music?

    having trouble downloading music from itunes store, some downloads play well before i purchase, but after my purchase the music has skips on playback?

  • Cropping in LR5 (and 4) not open the photo in PS CC

    Hello need to know if someone is experiencing this issue. When I crop a photo in LR5 or 4 and open it in PS cc, the photo is not opened. If I go back and reset the cropping, then the photo and all edits made are exported and visible in PS cc That s h