Altering a DOM once it has been created after parseing an XML file

Does anyone know of a nice easy way to edit a DOM once I have parsed it in so that I can write an altered XML file back to disk. (I can do the reading and writing easy enough, I just need the editing part.
I used to have code that worked if the child node you altered was directly off the root but I need something a bit more genric so that I can say:
replace(Document doc, String tag, String sub_tag, String item);
Where doc is the current DOM, tag is the main tag (not always the root), sub_tag is the specific tag I want to alter and item is the value I want to set the sub_tag to.
i.e. I want to read in XML like
<root>
<name>aname</name>
<blob>ablob</blob>
<sub>
<name>subname</name>
<item>anitem</item>
</sub>
</root>
and have one method where I can change the root name or the sub name.
Any ideas ?

FYI here is how I did it in the end.
* Finds where the child tag we are looking for occurs and then replaces it with
* the a modified clone of the child.
* @param doc The Document to alter.
* @param parent_tag The tag to alter.
* @param child_tag The sub_tag that will be altered.
* @param item The item to insert as the value of a tag.
* @param index_one The index of the parent tag incase there is more than one.
* @param index_two The index of the child tag incase there is more than one.
* @return The modified document.
private Document putItemInDoc(Document doc, String parent_tag, String child_tag, String item, int index_one, int index_two)
Document tempDoc = doc;
Element root = tempDoc.getDocumentElement();
boolean found = false;
Node parent = null;
NodeList matches = tempDoc.getElementsByTagName(parent_tag);
//get the parent node we know the child to be on.
parent = matches.item(index_one);
NodeList childList = parent.getChildNodes();
int count = 0;
int i = 0;
do{
if((childList.item(i)).getNodeName().equals(child_tag))
if(count==index_two)
Node child = childList.item(i);
Node clone = child.cloneNode(true);
clone.getFirstChild().setNodeValue(item);
found = true;
System.out.println("found");
//replace child node with modified clone.
tempDoc.getElementsByTagName(parent_tag).item(index_one).replaceChild(clone,child);
else
count++;
i++;
}while((i<childList.getLength())&&(!found));
return(tempDoc);

Similar Messages

  • How to insert condition on PO once GR has been created

    Hi all,
    I want to allow users to insert conditions on Purchase Order once Goods Received has been created. How do I do that?
    Thanks,
    Nas

    Hi
    You can add conditions in change mode ME22N.But it will not change the your Material documents that are already posted.Conditions applicable for balalnce quantity.
    You have to cancel your material documents and do fresh GR to reflect the changes for already GR done quantity.
    Regards
    Ramakrishna

  • How to close PR automatically once Contract has been created?

    Dear All,
    Please help me with this issue. The requirement here is from PR (with WBS Element) --> Contract --> PO (partial payments, total will be contract value which is adopted from PR)
    How do i automatically close PR once this PR has been adopted into a contract and saved.

    hi
    set message 06 076 as error in customization
    sproMaterials ManagementPurchasingEnvironment DataDefine Attributes of System Messages
    Vishal...

  • Is there anyway to remove a spawned template once it has been created?

    The current page setup has a button with a 'Mouse Up' action which runs a javascript code:
    var a = this.getTemplate("HS");
    a.spawn();
    The script works fine, however, every time the button is pressed a duplicate template is created and so on. I'd like to find a way so that if the button is pressed more than once, either the previous template is removed or is replaced each time the button is pressed.
    Thank you,
    Mdog

    You can delete a page that was added as a result of spawning a template using the doc.deletePages JavaScript method. But if you only want to allow a template to be spawned once, there are better ways to approach the problem. As script can check to find out how many pages are currently in the document and not spawn if it's already been done. It's easier to not do something if not needed rather than undo.

  • How to have real time data in a lookup or how to update a lookup once it has been created?

    Hi,
    I have created a lookup from an existing table and am using it to match incoming data. I would like to refresh the lookup once  a day. Is this possible. If yes how do I go about it?
    Regards
    Prabha

    If you are looking up onto staged data, just snapshot the data once a day.
    Or you could just do an External Lookup, where there is no need to refresh the data as you can just look it up dynamically.
    You will not get any 'fuzziness' with this approach.

  • Can I change my iCloud email address once it has been created?

    I found I cannot change the email address with the @me.com ending. I think it is associate with the apple ID and I tried to deleted the iCloud account but it seems only "sign out" and when I signed in iCloud with my apple ID everything is back....

    Hi sabouse,
    Yes you can change your printer's ePrint address:
    Sign into ePrintCenter.com.
    At the top of the ePrint box, next to the printer's ePrint address in blue you should find a change button.
    If I have solved your issue, please feel free to provide kudos and make sure you mark this thread as solution provided!
    Although I work for HP, my posts and replies are my own opinion and not those of HP.

  • How do I change template designs once a form has been created using another template design?

    How do I change template designs once a form has been created using another template design?

    I talked to a service Representative and he told me there isn't a function to change a form using one template to a different template. For example, I used template for "Accommodation registration" and wanted to change it to "admissions application." I was hoping I could just select a "Change template" rather than having to copy/paste everything to the new template. But that's what i had to do. Maybe the next version of this software will make it easier to change design templates.

  • SD How to create IDoc once Sales Order Invoice (Billing) has been created ?

    Hi,
    How to create IDoc once Sales Order Invoice (Billing) has been created ?
    I.e Once you click on save button of Invoice , IDoc Should genrate Automatically.
    Thanks

    Hello,
    Go to T.code VV31 and select the billing output type and select the access sequence required and in the details screen of create condition records give all the required entries for eg: may be Billing Type, Sales Organsiation etc.and in the medium choose the option as 6(EDI) and time select as 4 that is immediately after saving the document.Also please ensure that particular partners for whom idoc should be generated they need to have partner profile setup with the billing message types. Hope this helps.

  • How to create IDoc once Sales Order Invoice (Billing) has been created

    Hi,
    How to create IDoc once Sales Order Invoice (Billing) has been created   ?
    I.e Once you click on save button of Invoice , IDoc Should genrate Automatically.
    Thanks.

    Hi,
    We need to do custom configuration for this scenario such that an output type will be attached when ever an INVOICE is created.
    Refer to application V3 in NACE. The Output type should contain an entry with transmission medium: Distribution (ALE).
    for example check the customization done for an output type in NACE.
    Goto NACE ---> Select an application V3 ---> Click on processing routines ---> select the output type (Eg: RD00) ---> Click on Details button  (CNTRL + SHFT + F2) which gives the configuration info.
    For example we can generate the IDOC based on the settings in partner profiles for the customer (Sold To)
    With Regards,
    Dwaraka.S
    Edited by: Dwarakanath Sankarayogi on Jan 29, 2009 8:16 AM

  • Can we change customer account name once a quote has been created ?

    Can we change customer account name once a quote has been created ? Currently the customer account number becomes read only when the quote header has been created. This is true for both Forms Quoting and HTML Quoting.

    Presently the feature of changing customer name for Quote is not supported.

  • Why i'm getting exception InvalidOperationException: Invoke or BeginInvoke cannot be called on a control until the window handle has been created ?

    I have a backgroundworker1 dowork event and inside:
    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    BackgroundWorker bgw = (BackgroundWorker)sender;
    if (bgw.CancellationPending == true)
    return;
    else
    this.BeginInvoke(new MethodInvoker(delegate
    timer1.Stop();
    Button1Code();
    timer1.Start();
    trackBar2.Enabled = false;
    trackBar1.Enabled = false;
    while (true)
    bitmaps = ImagesComparison.get_images_with_clouds(b1);
    for (int i = 0; i < bitmaps.Length; i++)
    ConvertTo1or8Bit.BitmapToGIF(bitmaps[i], @"c:\convertedgifs\" + i.ToString("D6") + ".gif");
    break;
    The exception is on the BeginInvoke part.
    In the last few days i was running the program many times and i didn't have this exception even once.
    And now every times i'm running it i'm getting the exception.
    System.InvalidOperationException was unhandled by user code
    HResult=-2146233079
    Message=Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
    Source=System.Windows.Forms
    StackTrace:
    at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
    at System.Windows.Forms.Control.BeginInvoke(Delegate method, Object[] args)
    at System.Windows.Forms.Control.BeginInvoke(Delegate method)
    at mws.ScanningClouds.backgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) in d:\C-Sharp\Download File\Downloading-File-Project-Version-012\Downloading File\ScanningClouds.cs:line 715
    at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
    at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
    InnerException:
    Line 715 is: this.BeginInvoke(new MethodInvoker(delegate

    Where are you starting the background worker from?  Possibly the constructor of the form?
    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

  • How to clear a private static class attribute once it's been created?

    <pre>I'm working with an instance of a complex Class object that has been created using the function module <br>HRXSS_CAT_APPLICATION_INIT. The Class object that I am trying to work with is<br> CL_XSS_CAT_BUSINESS_LAYER and in particular its Static Private component attribute PROFILE.<br>
    The issue that I am having is that the first call of this function module creates and populates the Static Private component attribute, <br>PROFILE, for the instance of this Class and I do not know how to initialize it once it's been created. The PROFILE attribute is an <br>object reference to an instance of Class CL_XSS_CAT_PROFILE. <br>
    I want to reset/intialize this Static Private component. I can then call a Class Method with<br> different parameters so that it repopulates PROFILE with different attributes. <br>There is no Public method to do this in CL_XSS_CAT_BUSINESS_LAYER and even the Private method<br> INIT_PROFILE, the logic first checks to see if the PROFILE component is initial before creating a new PROFILE<br> object instance. All the Attributes of the CL_XSS_CAT_PROFILE object are Static and Private.
    <br>
    I would appreciate any insight anyone might have in how to reset/initialize this Class component attribute.<br><br>
    Thanks much,<br>
    <br>
    Graham<br>
    Sample code snippet is as follows:
    <br><br>
    DATA: lr_cats_application_rfc TYPE REF TO IF_XSS_CAT_APPLICATION_RFC,
    lr_core TYPE REF TO IF_XSS_PT_APPLICATION_CORE,
    lr_core TYPE REF TO CL_XSS_CAT_1_APPLICATION_CORE,
    lr_instance TYPE REF TO CL_XSS_CAT_APPLICATION,
    lr_business_layer TYPE REF TO CL_XSS_CAT_BUSINESS_LAYER,
    lr_profile TYPE REF TO CL_XSS_CAT_PROFILE,
    lr_profile_temp TYPE REF TO cl_xss_cat_profile.
    DATA: l_employee TYPE pernr_d.
    DATA: l_employee_tab TYPE rhxss_cat_employee_t.
    CASE im_command.
    WHEN 'DATESELECTION_PRVPERIOD'.
    *-> navigate to object component reference for CL_XSS_CAT_PROFILE instance
    lr_cats_application_rfc = im_ref_to_parameter_cache->REF_TO_APPLICATION.
    *-> navigate to object component reference for CL_XSS_CAT_1_APPLICATION_CORE
    lr_core ?= lr_cats_application_rfc->get_core( ).
    *-> navigate to object component reference for CL_XSS_CAT_BUSINESS_LAYER
    lr_business_layer = lr_core->business_layer.
    *-> navigate to object component reference for CL_XSS_CAT_PROFILE
    lr_profile = lr_business_layer->get_profile( ).
    l_employee = im_ref_to_parameter_cache->pernr.
    append l_employee to l_employee_tab.
    <br><br>
    *THIS IS WHERE I AM HAVING ISSUES...I WOULD LIKE TO CLEAR/INITIALIZE THE STATIC PRIVATE COMPONENT<br> LR_BUSINESS_LAYER->PROFILE BEFORE CALLING THE METHOD INITIALIZE_FOR_TIME_RECORDING<br>
    <br>
    <br><br>*THE FOLLOWING LINE FAILS ON A SYNTAX CHECK WITH 'FIELD "PROFILE" IS UNKNOWN. IT IS NEITHER IN <br>ONE OF THE *SPECIFIED TABLES NOR DEFINED BY A "DATA" STATEMENT
    <br>
    clear: lr_business_layer->profile.
    CALL METHOD lr_business_layer->initialize_for_time_recording
    EXPORTING
    im_employee_tab = l_employee_tab
    im_profile_id = 'MODAPPR1'
    im_startdate = sy-datum
    EXCEPTIONS
    pernr_not_enqueued = 1
    no_pernr_for_user_found = 2
    profile_not_found = 3.</pre>
    Edited by: Matt on Aug 1, 2009 12:44 PM

    OK...I apologize but I did not dig deep enough to see that the Enhancement Framework allows for the addition of Methods to Classes/Interfaces. Most of this ABAP OO stuff is still quite new to me so I'm struggling with syntax and what is and isn't possible based on how everything is declared. I guess now that I know I can do this I am having some problems understanding how singleton Class objects work and how to 'reset' them.
    The Class instance based on CL_XSS_CAT_BUSINESS_LAYER has a Static Private attribute PROFILE that is an object reference to the singleton Class instance CL_XSS_CAT_PROFILE.
    The singleton Class instance of CL_XSS_CAT_PROFILE has all of its attributes set to Static Private. If you look at this Class in SE80 you see that one of its attributes is also called PROFILE and is an object reference variable to itself.
    So the issue I am having is how to go about 'initializing' this singleton object so that I can 'recreate' this singleton object using a copy of the existing S
    I used the enhancement framework to create a copy of the CL_XSS_CAT_BUSINESS_PROFILE Instance Private Method INIT_PROFILE , called in INIT_PROFILE2, but I am not sure how to 'clear/reset' the instance of the CL_XSS_CAT_PROFILE object.
    Since PROFILE is an attribute of the CL_XSS_BUSINESS_LAYER object, I thought that a simple CLEAR PROFILE would reset the object but this is not the case. Within this method the FREE clears the value of the reference variable PROFILE but as soon as you step into the method me->init_profile, the value of PROFILE goes back to what it was. I need for all of the CL_XSS_CAT_PROFILE instance attributes to be reset or initialized so I can fill them again. I think I'm getting confused on the scope of things...should I be enhancing the CL_XSS_CAT_PROFILE Class with 'setter' methods so I can initialize all of the Static Private attributes that way instead of trying to clear all the attributes at a higher call level?
    Any assistance with helping me with my thought process or approach to this would be much appreciated.
    METHOD INIT_PROFILE2.
    FREE PROFILE.  >>> is reset but it does not carry through to next method call and does not clear all the attributes of the object referenced in PROFILE
    CALL METHOD me->init_profile
    EXPORTING
    IM_PROFILE_ID = im_profile_id
    etc...

  • CUP: Delete user certain time after request has been created

    Hi,
    Is it possible to define in CUP a delete account workflow that once the request has been created user deletion waits some time (i.e 1 month) before user is finally deleted? We would need a workflow without any approver.
    Delete User request creation >> 1 month >> User is deleted
    Thanks in advance. Best regards,
      Imanol

    Hi,
    Automatically deleting user IDs after a specific # of days is not possible in CUP. However, while creating the stage, you can define the wait time and then trigger the escalation. You can make the escalation to the Security Manager who can immediately take up the proper action, i.e., deleting the ID or making it inactive.
    Infact, this is the reason why it is recommended to have an alternative approver.
    Hope this addresses your question.
    Regards,
    Raghu

  • 5W332 No task has been created-HELP

    Hello
    We have a problem in workflow area. When trying to create an standard
    task TS (transaction pftc) I get transport request and ewerything seems
    ok and the message "standard task saved".
    However when exiting "pftc" I get message "5W332 No task has been
    created".
    Later on I can not invoke the task(I get the number in transport
    request objects)
    For 5W332 I do not find suitable note.
    Maybe the problem is that systam was upgraded from 3.0 to 4.7 ext2.0.
    How to solve this

    Hi,
    Once you create the task can you see the same in the Transport Organizer (SE01)? Just go into SE01 and choose to display and browse through and find whether the task is there?
    Also within workflow when you are specifying the task to be as a workflow step try using the "TS" prefix to the number.
    Hope this helps,
    Sudhi

  • How to change the internal order type when it has been created?

    There is an internal order, when it being created, the user chose the incorrect order type and save it. but the internal order number is useful. so we just want to change the order type or delete the order to release the number.  so can you give me some solutions to solve it. I can not find the way neither change the order type nor delete it.  thanks very much.

    You are unable to change the internal order type once an internal order has been created, however you can delete the IO if there haven't been any postings made.
    In change mode (tcode KO02), go into the internal order.  Go into the following menu:  Edit > Deletion Flag > Set.    Before you exit the IO, save the master record.
    Depending upon your archiving settings, you should then be able to select the menu path:  Edit > Set Deletion Indicator.
    If the IO isn't deleted, you can "clobber" it by going into the IMG and deleting the IO using the function "Delete Test Data".  This should only be done by a technical person to ensure that a mass-delete doesn't occur.
    Please note that if the IO was an internally assigned number, you might just want to block it and re-use it later.
    Hope this helps.
    Kylie

Maybe you are looking for

  • Navigate from a chart to another tab page

    I have a requirement to navigate from a chart to another tab page. Right now my implementation requires that I select one of the bars on the chart to navigate which also performs filtering. I want to be able to click any area on the request (not just

  • Configure Apache httpd.conf for struts requests

    Hi everyone, I am not sure if this is the correct place to ask this question, but I have been struggeling with this for a number of hours over the past few days and can't get it to work. I have a standard Apache2-Tomcat installation on a solaris mach

  • All pruchased materials to batch management

    Hi Gurus, Can anybody please throw some light on the following scenario. The business is proposing to batch manage all the materials that we buy. What are the implications that we will be facing by going this way? What technicaltities that i need to

  • Setting the PF Status for ALV

    Hi all, How it would be possible to create a PF Status for ALV display. I want to add one button my ALV report. Thanks. Harshad.

  • Wireless Download speed much slower than it should be

    Wireless Download speed on Belkin N300 is only 1.5 mps and hard wired speed is 50 mps.  Firmware is up to date, what else can I do??  What is the Wireless Router that Comcast recomends??