Bug or By Design?

Hi,

I recently had a problem with one of my XPath expressions which led me 
to believe there might be a bug in XmlNode, although it could be by 
design since I didn't find anything in the KB.

Consider the the code appended below. The function CleanEmptyElements 
removes all empty elements from the document using a XPath expression.

As you will notice in the code, I add two empty elements. If you check 
the resulting testXml.xml file, the "SpecialEmptyElement" element, 
though emtpy is still present.

The only special thing about it is that I assign a null string to the 
InnerText property of its node. As far as I know, this shouldn't make a 
difference, it should still be an empty element which is confirmed by 
the output of the file.

However, if you step through the code with the debugger, you will notice 
that as soon as I assign the null string, a new node gets added and the 
HasChildNodes property gets set to true.

If you try the same with the InnerXml property, you get the behavior I 
was expecting, which is that nothing happens. So there seems to be an 
inconsistency here unless I'm mistaken.

So, is this a bug or normal behavior?

Thanks

using System;
using System.Xml;

namespace EmptyElement
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			XmlDocument myDoc = new XmlDocument();

			XmlNode currentNode = myDoc.CreateElement("Root");
			currentNode = myDoc.AppendChild(currentNode);

			XmlNode tempNode = myDoc.CreateElement
("EmptyElement");
			currentNode.AppendChild(tempNode);

			tempNode = myDoc.CreateElement
("SpecialEmptyElement");
			tempNode.InnerText = null;
			currentNode.AppendChild(tempNode);

			CleanEmptyElements(myDoc);

			myDoc.Save("c:\\testXml.xml");
		}

		static void CleanEmptyElements (XmlDocument myDoc)
		{
			int i;
			XmlNodeList elementsToRemove;
			
			do 
			{
				elementsToRemove = myDoc.SelectNodes("//*[not
(node())]");
				
				for (i = 0; i < elementsToRemove.Count; i++)
				{
					elementsToRemove
[i].ParentNode.RemoveChild(elementsToRemove[i]);
				}
			} 
			while(elementsToRemove.Count > 0);
		}
	}
}
0
pollux (3)
5/23/2005 7:06:31 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
853 Views

Similar Articles

[PageSpeed] 29


Pollux wrote:


> I recently had a problem with one of my XPath expressions which led me 
> to believe there might be a bug in XmlNode, although it could be by 
> design since I didn't find anything in the KB.
> 
> Consider the the code appended below. The function CleanEmptyElements 
> removes all empty elements from the document using a XPath expression.
> 
> As you will notice in the code, I add two empty elements. If you check 
> the resulting testXml.xml file, the "SpecialEmptyElement" element, 
> though emtpy is still present.
> 
> The only special thing about it is that I assign a null string to the 
> InnerText property of its node. As far as I know, this shouldn't make a 
> difference, it should still be an empty element which is confirmed by 
> the output of the file.
> 
> However, if you step through the code with the debugger, you will notice 
> that as soon as I assign the null string, a new node gets added and the 
> HasChildNodes property gets set to true.

If you set InnerText to null the element gets one text child node which 
is empty. I don't know whether that is intended but that seems to be 
what happens.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
5/24/2005 11:18:30 AM
Reply:

Similar Artilces:

namespaces and protected static members VC .NET bug?
I found bug when use namespaces in mfc application. When I wrote DECLARE_MESSAGE_MAP/BEGIN_MESSAGE_MAP in base (CDialog-derived) class A and in class B : public A (A and B in different namespaces). I narrowed this problem to simple peace of code: class A { protected: static int f; static int *p; public: A() {} ~A() {} }; int A::f = 1; int *A::p = NULL; namespace some { class A : public ::A { static int f; static int *p; public: A() {} ~A() {} }; int A::f = 2; int *A::p = &::A::f; // this line produces error } This code does not work, VC compiller said: error C2248...

Transactions By Category Report Bug (Money 2005)
All, I'm experiencing a problem that I can't seem to work around and I hope somebody can help me out. I ran the transaction by category report and selected category A. I then went to the category setup screen and moved category A into B. I then went back to the transactions by category report and this time it won't open. Instead, it acts like it's going to open, but then immediately reverts back to the report menu screen. I'm pretty sure it's doing that because the last selected category the report ran was for category A and that category doesn't exist anymore...

BUG? Outlook 2003 Not Responding
Hi all, I'm currently running Outlook 2003 (11.5608.5606) along with Active Sync 3.7 (Build 3083). I have the *Hide When Minimized* option set Outlook (thanks MS!) Since my upgrade, I've noticed the following behaviors: When my pocket-pc is disconnected/off: If I *minimize* Outlook, it hides itself in the system tray, and can (almost) always be restored. If I *close* Outlook closes, and can be restarted. When my pocket-pc is connected/on: If I *minimize* Outlook, it hides itself in the system tray, and can (almost) always be restored. However if I *close* Outlook Outlook minimizes ...

Many to Many Design Tangle
I appreciate the value of this helping community! I have a question that follows an earlier response that helped me in dealing with a many to many relationship but has me currently tangled up in my re-design. I have a medical observation database for many subjects, with specific symptoms that are repeatedly measured, sometimes by different observers. A previously created FrontPage form exists wherein specific medical history is obtained (will be phased out and replaced with an Access form) and the 60 plus symptoms are first presented showing a default value of zero. The observer ide...

OL2003 Signature Bug?
I have four pop-mail accounts in a single profile. I'll call the Accounts A, B, C, and D. "A" is the default account. In OL2003, you are able to create a different signature for each account. I have created "New Message" and "Reply-to/Forward Message" signatures for two of the accounts (A and C). When creating a new message, the signature for A appears correctly by default. If I switch the "send from" account to C, the signature for C replaces the signature for A. This is expected. If instead, I switch to accounts B or D, the signature...

Money 2006 net worth bug
I have noticed that one of my net worth over time favorite reports refuses to load. If I watch the CPU, it appears that $ is in an infinite loop with the load bouncing back and forth between 50 and 80%. But the really amusing thing is this: during the loop if I select "custom date", change either the start or stop date (move either to a new date, or just touch one - change a date and move it back) and select the APPLY button, the load will converge. If you select the OK button, the load will not converge. I have saved a net worth report that converges and attempted to reload...

Is this a bug or not?
I replied to an email that was archived in Outlook 2007. The 'sent' copy was placed in the archived sent folder instead of the one in my personal folders. Is this normal or a bug? Is there anyway that I configure responses to archived 'mails to be put in the current sent folder? TIA. Cheers, Guy ** Stress - the condition brought about by having to ** resist the temptation to beat the living daylights ** out of someone who richly deserves it. "Dr Teeth" wrote in message news:db8si3lpuejhnpm3luacpu2rkkaef66stt@4ax.com... > I replied to an email that was archiv...

Bug in queue an activity association
When I see, for example, in my work queue, an email, and I make the following steps: 1. Open Email in New Window (from work item queue) 2. I delete email (not queue, just Email) 3. When I return to queue, even if I refresh, email is still there in my queue. 4. When I try to open email again from queue, I get error because record is not there anymore. Invistigatin further, I saw that ActivityParty and ActivityPointer tables doesn't have activityid, but queueitembase table has not deleted reference. This seems an error, and as workaround, I need to execute SQL directly (which btw is n...

BUGS BUGS BUGS
Dear Microsoft. I can understand programming bugs - you invent, you create, everyone makes mistakes etc etc. But how on earth can you have bugs in financial calculations? Take Finance 101 book. Replicate formulas. DON"T CHANGE THEM! I have already complained about mistakes in calculating bond yields in M2005 (has it been fixed?) where accrued interest is simply disregarded in calculations. Performance calculations in multiple currencies ARE ALL WRONG!!! here is example "buy" any asset in the account which is in a currency different to your base (say base is US$ and a...

Access 2007: bug? quick filter list is sometimes empty
Access 2007 has a great new feature which allows to easily filter by selecting different values from a drop down box on top of each column. However, sometimes the list of values simply is EMPTY in some columns. It seems that this has to do with the complexity of the underlying query. Does anyone know how to circumvent this? Or is it simply a bug? Kind regards Georg When the list of unique choices gets too big they don't show. You have some control over this office button/access options/current database/Filter lookup options (look at bottom of screen). It takes tim...

_USE_MATH_DEFINES bug
There is an interesting problem with the _USE_MATH_DEFINES preprocessor symbol, which is used to get math constants defined. There are two different compilation models used for Release and Debug configurations, such that using _USE_MATH_DEFINES as it is supposed to be used in a Debug configuration compiles successfully, but using it in a Release configuration causes an undefined symbol error. For details see http://www.flounder.com/msdn_documentation_errors_and_omissions.htm#_USE_MATH_DEFINES joe Joseph M. Newcomer [MVP] email: newcomer@flounder.com Web: http://www.flounder.com MVP Tips...

Furtive Bug!
On different worksheets are (Forms) Buttons with the below macros assigned to them. "GoToUtilizationChart()" works perfectly, but "GoToPPVChart()" only brings up the "Metrics" worksheet and cursors to A1 - it does not select the chart. Chart names are confirmed correct. To test the problem, I copy/pasted the "Utilization" macro and substituted "PPV" and "3" in the code - still doesn't select the PPV chart. Can someone help me exterminate this bug?! Appreciate any help... Phil Sub GoToPPVChart() Sheets("Metr...

Bug in CFrameWnd::OnDDEExecute
I noticed that my app did not respond to a DDE msg (double-click on doc in Win Explorer), when the app was already running. I traced this problem to an error in the code in CFrameWnd::OnDDEExecute. This MFC routine stores a pointer to the DDE command string into "LPCTSTR lpsz" but passes a pointer to an empty string "TCHAR szCommand" to the app, forgetting to copy the string from lpsz into szCommand: TCHAR szCommand[_MAX_PATH * 2]; LPCTSTR lpsz = (LPCTSTR)GlobalLock(hData); ... ... //there should be a copy in here someplace??? ... ...

Getting a -1 Status in Disqualify Lead
I'm getting a -1 status when I try and disqualify a lead. When I click on the picklist I get an IE Script Error: 'firstChild.firstChild.children[...].offsetTop' is null or not an object My guess is that the picklist values were deleted or customized or something. Where can I edit the Disqualify - Status picklist values? Any ideas on what could be happening? Just a follow up. Hopefully it will help someone. Turns out somehow our XML file included duplicate contact sections. We exported the XML, sent it to Microsoft support, they fixed the XML file and sent it back. We imported i...

Could this be a bug?
We've been intergrated with QBPRO for about a month now and everythings been going well. However, when there's a Payout for the day it doesn't get deducted from the cash deposited. All the accounts are mapped correctly so it has nothing to do with it. Example: We take in $602 cash and have a $2 payout. The tender summary report is accurate, it says $602, the amount taken in. The Z report is accurate, it says we had a $2 payout and $600 to deposit, $602 minus the $2 payout. The problem is that $602 gets deposited by RMS into QB, therefore I have to go into QB and manually adj...

optimization bug? CString bug? initialization bug?
I have a very interesting problem that I have not been able to explain to my satisfaction. I would greatly appreciate any help in the matter. Here is an outline of the code: void CMyClass::MyFunc() { CString szTemp; long nResult = GetResult(); switch (nResult) { case ... case ... long otherResult = GetOtherResult(); switch (otherResult) { case ... case ... szTemp = GetString(); ...use szTemp... break; } break; } } Th...

WMP12 Bug with Large Libraries (confirmed and reproducable)
I have been working with a few of the guys over at we got served and have discovered a live bug in the windows media player version as shipped with windows 7 ultimate x86 I have a home server (WHS) and a media center (Win7). the home server runs PP3 and has 42,000 mp3's in the music share. All mp3s are well tagged and have embedded album art. when windows media player starts scanning the folder in order to import music it gets to 32750 (integer maximum value) and hangs leaving the graphical elements of media player corrupted. this stays like this for approx 5 minutes...

Bug in DragQueryFile()?
I'm using DragQueryFile() to enumerate the files dropped on my target window, and everything seems to pretty much work fine, except that, if I select n files in an Explorer window and drag them into mine, I get the last file in the list first (i.e., for index 0), and then all the remaining files (1 to n-1) in the correct order. Is this a known problem? Is there a fix? Am I doing something wrong? Thanks. >I'm using DragQueryFile() to enumerate the files dropped on my target window, >and everything seems to pretty much work fine, except that, if I select n >files in an ...

Apparent bug in XmlSerializer or XmlTextWriter or something
Hi. I have a really simple set of classes that writes 2 pathnames to a xml file. I can write the default ok. Then if I change 1 pathname to a shorter one, then rewrite the xml file, the remains of the old pathname, and closing tags are left on the end resulting in an invalid XML file. XmlSerializer.Deserialize gives a System.InvalidOperationException with additional information: Error in the XML document. My default file for example looks like: (sorry about the wrapping if its wrapped) ��<?xml version="1.0" encoding="utf-16"?><settings xmlns:xsd="ht...

PrintWindow bug
Hello, I'm writing an app that uses the GDI PrintWindow routine to capture a snapshot of a window. The problem is that some window with an image redraw that image covering the client area. Powerpoint is one such window. Anytime I try to capture it, all images on the page are redrawn up and to the left, creating double images. The worst example is the desktop which redraws any background image on top of all other windows, making it look as if all windows have been deleted. Does anyone have any experience with this? I need a clue. Thanks, Rick ...

Bug
Try: =68.60-60.00 =8.60 The answer is FALSE. No Bug!! Take a look here! http://support.microsoft.com/kb/214118 and about 10,000 other sites that you can find with google. Regards Martin <amvana@gmail.com> wrote in message news:1191138811.888873.293990@d55g2000hsg.googlegroups.com... > Try: > =68.60-60.00 =8.60 > The answer is FALSE. > ...

Frame redrawing/refreshing bug
Hello fellow newsgroupies, I posted a question yesterday asking how to prevent a child or popup window from being resized. The solution was to modify the windows style by removing the WS_THICKFRAME and WS_MAXIMIZEBOX. However this results in the frame of the window not being redrawn or refreshed correctly - speckles and colours appear around the edge. Has anyone else witnessed this and if so does anyone know of a fix? Many thanks in advance, 'Newsgroupie' England Correction! The refresh / redrawing bugs do not appear if you modify the style from with in 'PreCreateWindow'...

Bug in WDK Install process
I tried to install the WDK (7.1.0) from a burned ISO image. However, a few seconds after the autostart shows the main DDK menu, I get a KitSetup Runtime Initialization Error! (Code:0x0007). The installer immediately crashes and exits. The problem is that 1) I use a dedicated SATA drive for my temporary file system, and 2) I have defined the TEMP environmental variable in the root of that drive (T:), so there's a backslash ending the TEMP variable string. I can confirm that ANY TEMP envar with a trailing backslash will cause the installer to fail catastrophically, so it&#...

Possible Intellisense Bug?
Hello, While using Visual C++ .NET 2003 on a large project that has a solution that consists of 4 projects, I began noticing that sometimes Intellisense didn't work on somethings. Is this related to the size of my project, or is this a bug? When I deleted the ncb (Intellisense database file) the problem was solved for a little, but then it reappeared. The bug in particular is when you get the dropdown menus while entering a line of code that references a object ie : CMyObject* Object; Object-> (intellisense should appear) Any ideas? Sincerely, James Simpson "J...

Is this MS bug or my bug
I got the following first chance exception in debug mode when program exit, if I run in release mode, it seem to be fine. it's running in win2003 VC7.1 environment. the callstack is like: kernal32.dll! 77e4af90() comctl32.dll! 70ae2072() comctl32.dll! 70ae20af() ..... walbumd.exe! ATL:: CTrace::TraceV(..) ntdll.dll! 77f685df() .... Walbumd.exe!CWnd::DefWindowProcA(...) Walbumd.exe!CThreadLocal<_AFX_THREAD_STATE>::GetData() Line 177+0xd 00000001() please see attached image file for detail. This bug is annony, I dont know how to get ride of it. Thanks zhi ma At what point does ...