|
I spotted this gem written by one of our developers that needed to copy an XML node from one XML document (source) into another (target). The variable naming's been changed to make it clearer.
Given 2 XML nodes:
XmlNode sourceNode = source.SelectSingleNode("BOOKS/BOOK[@id='1234']");
XmlNode targetNode = target.SelectSingleNode("COMPANY/BOOKS");
This is the code the developer wrote.
XmlElement bookElement = target.CreateElement("BOOK");
targetNode = targetNode.AppendChild(bookElement);
<big>targetNode.InnerXml = sourceNode.InnerXml;</big>
How performant do you think it would be compared to this?
XmlNode importedNode = target.ImportNode(sourceNode, true);
<big>targetNode.AppendChild(importedNode);</big>
I haven't bothered to do the tests but I guess stringifying some XML and then parsing it back again would be a tad inefficient!
|
|
|
|
|
Yes, I assume so. As once the node is created it's stored in memory ready to be attached to another node, whereas if the XML is "stringified" then I assume the text is parsed, the node generated and copied to memory and then attached.
The other obvious advantage is less code
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
At least he was trying to use Xml. I'm sick and tired of seeing questions where people are looking for nodes in an Xml document and just treating the whole thing as one big string.
|
|
|
|
|
At least we CAN blame VB for this one!
|
|
|
|
|
Yes, I remember in VB6 days when you had an MSXML2 and MSXML4 documents, stringifying the XML was the only way to copy data across from one to another. The MSXML parser didn't like you mixing different versions.
|
|
|
|
|
DrWheetos wrote: Yes, I remember in VB6 days when you had an MSXML2 and MSXML4 documents
Never, ever admit to remembering VB6 days. Claim you had amnesia or something instead. You'll only get tarred with a brush you don't want.
|
|
|
|
|
Yes, it would be a bit on the inefficient side.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Yes! buddy
|
|
|
|
|
If your product manager asked you to make a printer-friendly version of a webpage, how would you choose to implement it?
(A) Add a "print" parameter to your query string. In your CGI code, add IF statements where appropriate.
(B) Add a @media print section to the stylesheet.
(C) Write a 200-line Javascript function to walk through the DOM tree to remove unwanted navigational elements.
No points for guessing which choice was made by the previous maintainer of one of the web apps I'm working on now.
modified on Wednesday, August 27, 2008 8:07 PM
|
|
|
|
|
(D) Say, if you want it to print nice, don't use a webpage. Or maybe that's just me.
|
|
|
|
|
Let me guess, he picked (C)
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
and he wrote a buggy code to jeopardize the system and crash the user's browser to be appreciated by the management and promoted as a 'Technical Manager'.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
All the world's a stage,
And all the men and women merely players.
They have their exits and their entrances;
And one man in his time plays many parts... --William Shakespeare
|
|
|
|
|
Not just that, but perhaps the users would turn off javascripting on their browsers
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Good guess.
I showed him how to do (B) today, and he was impressed at how much simpler it was.
|
|
|
|
|
ClementsDan wrote: I showed him how to do (B) today, and he was impressed at how much simpler it was.
Cool. Hopefully, he learned from your example
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
And. You should know by now that macho-programmers don't take the easy route when you can write hundreds of lines of redundant code. It's a system or developing known as Advanced Redundant System Enhanced Helping Online Lexical Expressions.
|
|
|
|
|
You mean A.R.S.E.H.O.L.E., right?
|
|
|
|
|
No primary key or index on every table.
No view, No stored procedure, No trigger.
I'm not sure whether it even fit for 1st Norm.
This database is used by our company's previous accounting system. I've heard a colleague told me that they have to restart the system once (or more) per day.
|
|
|
|
|
Sounds like a third-party product we used to use. I suspect that the application read everything into memory and then just worked with it there.
|
|
|
|
|
Sounds like SAP to me. Have you seen the database? Talk about a coding WTF....
|
|
|
|
|
I once had to work with a database like that. It was just a huge number of tables, as described, but with the added bonus of *no* foreign key relationships. Evidently, all foreign keys and referential integrity was handled by the application.
|
|
|
|
|
There are still people who argue that there should be no referential integrity on production databases.
|
|
|
|
|
PIEBALDconsult wrote: There are still people who argue that there should be no referential integrity on production databases
That tends to be my preference, I prefer to code the referential integrity through the application code rather than embed it in the database.
I won't give the reasons why this can be a very good idea as there will be plenty of counter reasons as to why it is a very bad idea.
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
No referential integrity sometime acceptable.
But if you don't have key or index on every table, it will slow down query significantly. (For some complicated join query, it will be 10 to 100 times slower than the one with indexes).
Can you imagine you have to wait 20 minutes only to print a invoice? (And during this time, all the other people almost can't do anything)
If you design database like this, I would really hope I'll never cooperate with you.
|
|
|
|
|
Indexes - pwah!
Real men use table scans in their queries - indexes are for cheats
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|