Proper use of normalize(); XML spaces not removed

Ok so I was up till 3 AM trying to figure out why normalize is not removing white space. I have nothing left to normalize() except my brain. Any help would be appreciated.
Code snippit to remove children & parents
if( !elemSave ){
while( ((Element) n).hasChildNodes() ) {
((Element) n).removeChild( ((Element) n).getLastChild() );
((Element) n).getParentNode().normalize();
//have tried normalize here doesnt close the spaces
((Element) n).getParentNode().removeChild((Element) n);
//tried normalize here doesnt close the spaces
document.normalize();
return document;
------- Resulting XML ---------
<?xml version="1.0" encoding="UTF-8"?>
<Entity createddate="6/19/08" defaultrole="CONTR_CAND" id="93023" updateddate="2/6/09">
<Role>CONTR_CAND</Role>
<Property bisuniqueid="6172" name="SKILLS" occurrence="1">
<Attribute name="SKILL" sqldatatype="NUMERIC"/>
<Attribute name="YEAR_EXP" sqldatatype="NUMERIC"/>
<Attribute name="LEVEL" sqldatatype="NUMERIC"/>
</Property>
<Property bisuniqueid="4385" name="JOB_CAT" occurrence="1">
<Attribute name="JOB_CATEGORY" sqldatatype="NUMERIC">8253425</Attribute>
</Property>
</Entity>

find it odd that you can delete the child nodes of an Element and there is no space <Property name="something" /> but when you delete the Element that held the children you come up with an empty space.I have no clue what you're saying here. The whitespace around an element is held as a peer of the element, not its child.
Thanks for the idea kdgregory but I would rather use JDK. The project is open source. You could simply copy the relevant method into your own code (although the Apache license requires you to acknowledge the source):
    public static void removeEmptyTextRecursive(Element elem)
        NodeList children = elem.getChildNodes();
        for (int ii = children.getLength() - 1 ; ii >= 0 ; ii--)
            Node child = children.item(ii);
            switch (child.getNodeType())
                case Node.ELEMENT_NODE :
                    removeEmptyTextRecursive((Element)child);
                    break;
                case Node.CDATA_SECTION_NODE :
                case Node.TEXT_NODE :
                    if (StringUtils.isBlank(child.getNodeValue()))
                        elem.removeChild(child);
                    break;
                default :
                    // do nothing
    }There is still a dependency on Jakarta Commons-Lang StringUtils, but I'll leave the copying of that method up to you.
... although you really should start using utility libraries -- they exist because other people have run into the same issues.

Similar Messages

  • Message: cannot import xml, even after exporting using file, export, xml, and not touching the file

    I need to change the messages for a different language.  Has anyone been able to set this XML file to import?  Some of the content is in Norwegian, but don't how that will affect it. But it will not import a file, even if it was just exported.

    Hi Patrick,
    I tried few import/export scenarios in captivate 7 and it works fine for me. I think it will be a good idea if you can mail me the .xml file along with steps to reproduce the issue.
    My email id is [email protected]
    -Tamish

  • Why ribbon XML does not work in Excel 2007?

    I installed 4 VSTO Excel add-ins on an Excel 2007 PC today. The two that use a visual designer ribbon worked fine. But the 2 that use a Ribbon (XML) did not. The add-in starts ok. But the ribbon does not show. Why would that be?
    I wrote two more add-ins to demonstrate the problem. One puts an OK button on the ribbon using the visual designer. That add-in installs on the excel  2007 PC and works as it should. But the 2nd, an add-in that uses Ribbon (XML) to put a button on the
    ribbon, does not work.  The add-in does not display on the ribbon.
    Here is the code of the Ribbon (XML) add-in project.  How to get a ribbon (XML) ribbon to display in excel 2007?
    thanks,
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using Excel = Microsoft.Office.Interop.Excel;
    using Office = Microsoft.Office.Core;
    using Microsoft.Office.Tools.Excel;
    namespace ExcelAddIn4
    public partial class ThisAddIn
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    protected override Office.IRibbonExtensibility CreateRibbonExtensibilityObject()
    return new Ribbon1();
    #region VSTO generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InternalStartup()
    this.Startup += new System.EventHandler(ThisAddIn_Startup);
    this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
    #endregion
    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
    <ribbon>
    <tabs>
    <tab idMso="TabAddIns">
    <group id="ContentGroup" label="Content">
    <button id="Button1" label="ok" screentip="Text"
    onAction="Button_OnAction" supertip="Inserts text at the cursor location"/>
    </group>
    </tab>
    </tabs>
    </ribbon>
    </customUI>
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Windows.Forms;
    using Office = Microsoft.Office.Core;
    // TODO: Follow these steps to enable the Ribbon (XML) item:
    // 1: Copy the following code block into the ThisAddin, ThisWorkbook, or ThisDocument class.
    // protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    // return new Ribbon1();
    // 2. Create callback methods in the "Ribbon Callbacks" region of this class to handle user
    // actions, such as clicking a button. Note: if you have exported this Ribbon from the Ribbon designer,
    // move your code from the event handlers to the callback methods and modify the code to work with the
    // Ribbon extensibility (RibbonX) programming model.
    // 3. Assign attributes to the control tags in the Ribbon XML file to identify the appropriate callback methods in your code.
    // For more information, see the Ribbon XML documentation in the Visual Studio Tools for Office Help.
    namespace ExcelAddIn4
    [ComVisible(true)]
    public class Ribbon1 : Office.IRibbonExtensibility
    private Office.IRibbonUI ribbon;
    public Ribbon1()
    public void Button_OnAction(Office.IRibbonControl control)
    MessageBox.Show("Button_OnAction");
    #region IRibbonExtensibility Members
    public string GetCustomUI(string ribbonID)
    return GetResourceText("ExcelAddIn4.Ribbon1.xml");
    #endregion
    #region Ribbon Callbacks
    //Create callback methods here. For more information about adding callback methods, visit http://go.microsoft.com/fwlink/?LinkID=271226
    public void Ribbon_Load(Office.IRibbonUI ribbonUI)
    this.ribbon = ribbonUI;
    #endregion
    #region Helpers
    private static string GetResourceText(string resourceName)
    Assembly asm = Assembly.GetExecutingAssembly();
    string[] resourceNames = asm.GetManifestResourceNames();
    for (int i = 0; i < resourceNames.Length; ++i)
    if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
    using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
    if (resourceReader != null)
    return resourceReader.ReadToEnd();
    return null;
    #endregion

    Hello Steve,
    Most probably you have got an error in the ribbon XML markup. See
    How to: Show Add-in User Interface Errors for more information.
    I have noticed the following xml namespace:
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
    Use the following one instead:
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
    Also make sure that specified idMso values exist in Office 2007.
    You can read more about the Fluent UI (aka Ribbon UI) in the following series of articles in MSDN:
    1.
    Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
    2.
    Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
    3.
    Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

  • IPhone not removing played podcasts during sync(using the unplayed feature)

    Hi folks,
    I listen to a lot of podcasts. When I used an iPod the sync unplayed option. Once I listened to a podcast it was removed (saving space for more podcasts). With my iPhone I've got the options set up correctly (i.e. set at Sync Unplayed) but podcasts are not removed once I play them.
    I called up Apple support and their Tier II were able to confirm the problem and are sending it up to their engineers. Hopefully that'll mean a fix in the next software update.

    I am having the same problem.
    iTunes transfers all of my podcasts to my 2nd Gen iPod Nano (and replacement 3rd Gen iPod Nano), regardless if I specify 1, 3, or 5 “most recent” podcasts or even completely disable podcast syncing altogether.
    How do I know all my podcasts are being transferred?
    1. I see that iTunes is copying them during “Sync”
    2. The podcasts (almost 3 GB total if iTunes transfers all of my podcasts, under 100MB normally) take up space on my 4GB 2nd Gen iPod Nano, preventing me from syncing my music and audiobooks (around 2.22 GB)
    3. On my 2nd Gen iPod Nano, illicit podcasts can be found via “Artist”, “Album”, “Song”, etc.
    4. I see the podcast files when browsing my iPod using third-party software.
    What have I tried to fix this?
    1. Closed and reopened iTunes
    2. Checked to make sure I had the most recent version of iTunes
    3. Checked to make sure I had the most recent version of the iPod Software (1.1.3)
    4. Downloaded and reinstalled iTunes (7.6.29)
    5. Reset my iPod
    6. Restored my iPod from iTunes
    7. Reformatted and then restored my iPod
    8. Deleted and restored my entire iTunes Library via Time Machine
    9. Exported, deleted and re-imported my entire iTunes Library
    10. Deleted and re-subscribed to my podcasts
    11. Reinstalled OS X 10.5 (“Erase and Reinstall”)
    12. Purchased a 3rd Generation iPod Nano
    Steps to reproduce:
    1. Open iTunes 7.6
    2. Delete all podcasts, move files to trash
    3. Connect iPod Nano
    4. Uncheck podcast syncing and apply settings
    5. Subscribe to podcast via iTunes Store
    6. Sync
    7. Watch as the podcasts are synced to my iPod
    5. Confirm using third-party software (or browse to tracks on 2nd Gen iPod Nano via “Artist”, “Album”, “Song”, etc.)
    Apple Developer Connection Bug Report 5733581
    http://discussions.apple.com/thread.jspa?messageID=6563613
    http://discussions.apple.com/thread.jspa?threadID=1385258
    http://discussions.apple.com/thread.jspa?threadID=1387728
    http://discussions.apple.com/thread.jspa?threadID=1385175
    http://discussions.apple.com/thread.jspa?messageID=6563615
    http://discussions.apple.com/thread.jspa?messageID=6563619
    http://discussions.apple.com/thread.jspa?messageID=6209116

  • If I back up iMovie projects to an external drive does it take the media with it? I want to free up space and remove pictures that were in iPhoto...that were used as media by iMovie when project was under way. In short I want archive iMovie stuff

    If I back up iMovie projects to an external drive does imovie  take the media with it? I want to free up space and remove pictures that were in iPhoto...that were used as media by iMovie when project was under way. In short I want archive iMovie stuff. If I pull pics out of iPhoto, and later want to drag an archived projet bac into iMovie and the pics are no longer in iPhoto, will I be able to keep working in the project in iMovie?

    Very likely not, as the iPhoto's can be used for something else.
    More like it took a copy, or it's referencing that spot on the drive in the editable files and most likely made a copy to create a new permanent export file.
    Sample one picture and a iMovie file and see what happens.

  • I can not remove spaces from TEXT file..

    Hi All,
    please advise me why the following code not remove the spaces or tab from the text file.
        try
            FileReader fr = new FileReader("D:\\Test\\a.txt");
    BufferedReader br = new BufferedReader(fr);
    Pattern p;
      Matcher m;
    String line;
    String afterReplace = "";
      String inputText = "";
    while((line = br.readLine()) != null)
       inputText = line;
      p = Pattern.compile("\\s+|\t");
      m = p.matcher(inputText);
      System.out.println(afterReplace);
      afterReplace = afterReplace + m.replaceAll(" ") + "\r\n";
      System.out.println(afterReplace);
    fr.close();
          catch (Exception e){
      System.err.println("Error: " + e.getMessage());
      }my regards
    Wael

    many thanks for you , i try to used it for the following text but the results same.
    McNair was shot and killed last weekend in what police say was a murder-suicide.  (July 9)                      Nation / World                          By:  AP                                 
     Comments: text ( 0 ) |  video ( 0 )    + Add a comment        
          Be the first to  add a comment .                                                           
           1          2          3          4          5                 Your Rating               <br>                                                                                                                                                                                                                                                                                                       
        Popularity                                                                                                                                    Your Name:                Your Comment:                                                                                                 
     http://videos.kansascity.com/vmix_hosted_apps/p/media?id=4999903&amp;item_index=&amp;genre_id=00000840 
                                                                     Your Email:                                     Friend's Email:                                     Your Message:                                                                                                                                                                                                                          
    Top Videos                                       Nation / World                       
                    Sports                                       Entertainment                                       Business                                       Lifestyle                                       
    Archive                                       User Submitted                                       Politics                                       Ink                                       Local                                       
    Selects                                                                                                                   
     all                        Sort By:                  Most Recent        Most Popular   
              Highest Rated                                                                 Loading...      
                               <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
     All users : If you have not already done so, Click "Record a Comment" to begin. Next, click "Allow" to use your camera.<br><br>  
     Additional Info for Mac users : If you do not see video (after clicking 'allow'), do the following:<br>      Click on the blue "gear" icon   in the lower right corner to bring up the settings window.     Click on the webcam icon.       If you are using a built in iSight camera, 
    choose USB Video Class Video from the pulldown menu. You should see video immediately.<br><br>       Click "close" button.   
    Record! You must record at least ten seconds before 
    you can stop.                

  • HT4914 if you use iTunes match in order to create space and remove music from your hard drive, does that happen automatically when you subscribe and upload your music or is there another step to remove the music from your hard drive once you've uploaded t

    if you use iTunes match in order to create space and remove music from your hard drive, does that happen automatically when you subscribe and upload your music or is there another step to remove the music from your hard drive once you've uploaded to iTunes match?

    Welcome to the Apple Community.
    iTunes match won't automatically remove content from your computer, if you want to do that you will need to do it manually yourself.

  • Error message is showing while connecting to itunes - "This iphone cannot be used because the required software not installed. Run the itunes installer to remove the itunes, then install the 64bit  version of itunes - Pls Help

    I tried to install in my Sony Vaio Laptop - Model Name SVF15218SGW Serial No 54****************954. After installation of itunes, when i am trying to connect error message is showing as follows -
    "This iphone cannot be used because the required software not installed. Run the itunes installer to remove the itunes, then install the 64bit  version of itunes".
    i already installed 64bit version. but not connecting my iphone with itunes
    PLEASE HELP.!!!!
    <Personal Information Edited by Host>

    Hello Negaz
    When you uninstalled iTunes, did you uninstall it by using the article below or just uninstalled iTunes? The best practice is to remove not only iTunes, but also other associating software in the order that the first article give. If that does not work, then check out the second article for more troubleshooting options for connecting your iPhone to your computer.
    Removing and reinstalling iTunes and other software components for Windows Vista, Windows 7, or Windows 8
    http://support.apple.com/kb/ht1923
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/ts1538
    Regards,
    -Norm G.

  • When I connect my Iphone 5 to sync with my Itunes on my PC I get a message- This Iphone cannot be used because required software is not installed.  Run Itunes installer to remove itunes then install itunes again.

    When I connect my Iphone 5 to sync with my Itunes on my PC I get a message- This Iphone cannot be used because required software is not installed.  Run Itunes installer to remove itunes then install itunes again.

    After uninstalling and reinstalling Itunes- issue was fixed.  Thanks!

  • I switched to mountain lion and from Acrobat pro 9 to 10.  now safari will not open pdf files.  acrobat preferences says it is trying to use version9 to open and i removed version 9.  any ideas?

    I switched to mountain lion and from Acrobat pro 9 to 10.  now safari will not open pdf files.  acrobat preferences says it is trying to use version9 to open and i removed version 9.  any ideas?

    Make sure you have updated Acrobat X to the latest version 10.1.3.  They updated the PDF plug-in in 10.1.1:  http://kb2.adobe.com/cps/837/cpsid_83708/attachments/Acrobat_Reader_ReleaseNote_ 10.1.1.pdf#page=4

  • IOS Cangjie input method can not be used. Original with Space Bar word selection function is invalid, as soon as possible to solve, it will affect the most users in Taiwan and Hong Kong.

    iOS Cangjie input method can not be used. Original with Space Bar word selection function is invalid, as soon as possible to solve, it will affect the most users in Taiwan and Hong Kong.

    No PR1.2 Firmware update, No update for Nokia Messaging, No updates for Ovi Maps .... Why is the N900 the forgotten stepchild ?
    "PR1.2 is still being tested - http://twitter.com/luovanto/statuses/13087245356"
    Hong Kong Launch http://www.youtube.com/watch?v=pY8zCBzvQLo

  • Encore not using full available disc space

    So. I frequently burn DVDs with Encore with timelines that are 2 hours or longer. Beginning in CS5, Encore would start only using up 4.2GB of space even though the size of my disc image was 4.7GB. Before the material is rendered, Encore says it's using all 4.7GB, with a few MB left over. But once it's done rendering, sometimes there's an extra 500 MB unused. It doesn't always happen but usually does. If I click around in Encore a bit, the disc info panel updates to show all the extra unused space.
    This was not the case in any previous version of Encore. Tech support people tried to tell me this was a feature, that Encore was now including 10% of buffer space. What an idiotic feature, but ok, whatever.
    So I started trying to fool Encore by setting the disc size to 5.2 GB. And most of the time I'd come out w/ an image using all the available space on the DVD. Except, that doesn't always work. Right now I have a project that's 1 hour 45 minutes. When I render a disc of 5.2 GB size, that's exactly how much space the disc image takes up. Ok, so I re-render at 4.7 GB. Nope, it's gonna do 4.22 GB. WTF??? And then sometimes, for no clear reason at all, Encore will make a 4.7 GB image without me changing a thing.
    If this was really a feature, it's not implemented consistently, and then why tell me my disc is using 4.7 GB before rendering if Encore has no intention of using that much space.
    I brought this problem up back when CS5 came out--I talked to senior-level support people about it--and can't believe that two versions later it hasn't been fixed. It's wasting incredible amounts of my time.
    The cycle hasn't ended for as long as I've been buying Creative Suite...every version, lots of my long-standing frustrations are fixed, but Adobe manages to screw up one big thing. And I give in and pay for the next version in hopes that it gets fixed...but something else then gets screwed up. Another several hundred dollars later and now I guess I have to wait for CS7 to maybe have this work correctly.

    pezley wrote:
    Using Disk Utility I deleted the 2nd partition and merged the two. Disk Utility reports it now as one 120gb partition
    Welcome to Apple's discussion groups.
    In Disk Utility, if you select that drive and the "Partition" tab, what do you see as the partition arrangement?

  • Need to figure out how to remove an unknown admin password on a mac.  used the install disc with not luck. tried some commands in single user mode, no luck.

    need to figure out how to remove an unknown admin password on a mac.
    used the install disc with not luck. tried some commands in single user mode, no luck.

    need to figure out how to remove an unknown admin password on a mac.
    used the install disc with not luck. tried some commands in single user mode, no luck.

  • How to remove history in the location bar? Deleting history and then using "History" only in the settings for the location bar does not remove old history.

    I want to remove ''old History'' in the Location bar.
    I am using Firefox 3.6.13.
    "Clear recent history" does not remove the old History in the Location bar. And changing the setting to only show "History" does also not remove the old history.
    Pressing "Delete" on single lines when opening the list by clicking the arrow to the right in the location bar, remove the entries temporary. But next time you type in the location bar, the same suggestions are there.

    See:
    * [[Clearing Location bar history]]
    * [[Cannot clear Location bar history]]
    Entries in the location bar drop down list with a yellow (blue on Mac) star at the right end are bookmarks.<br />
    You can remove such a bookmarked item that shows in the list if you open that url in a tab and click the yellow star in the location bar.<br />
    This will open the "Edit This Bookmark" dialog and you can click the Remove button to remove the bookmark if you want to remove such a bookmarked entry.

  • I have installed itunes but get massage coming up saying cannot be used because required software is not installed, run itunes installer to remove itunes, then install itunes again. I have done this but still not able to connect my iphone, ipad or ipod.

    I have installed itunes, but when connecting the iphone, ipad or ipod it states the following:-
    Connot be used because required software is not installed run itunes installer to
    remove itunes, then install itune again.
    I have done this on a number od times, but still having the same message coming up.
    Please can you help me.
    Kind regards
    Caroline Jones

    Let's try a standalone Apple Mobile Device Support install. It still might not install, but fingers crossed any error messages will give us a better idea of the underlying cause of why it's not installing under normal conditions.
    Download and save a copy of the iTunesSetup.exe (or iTunes64setup.exe) installer file to your hard drive:
    http://www.apple.com/itunes/download/
    Download and install the free trial version of WinRAR:
    http://www.rarlab.com/
    Right-click the iTunesSetup.exe (or iTunes64setup.exe), and select "Extract to iTunesSetup" (or "Extract to iTunes64Setup"). WinRAR will expand the contents of the file into a folder called "iTunesSetup" (or "iTunes64Setup").
    Go into the folder and doubleclick the AppleMobileDeviceSupport.msi (or AppleMobileDeviceSupport64.msi) to do a standalone AMDS install.
    (If it offers you the choice to remove or repair, choose "Remove", and if the uninstall goes through successfully, see if you can reinstall by doubleclicking the AppleMobileDeviceSupport.msi again.)
    Does it install (or uninstall and then reinstall) properly for you? If so, can you get a normal iTunes install to go through properly now?
    If instead you get an error message during the install (or uninstall), let us know what it says. (Precise text, please.)

Maybe you are looking for