- Implementing Lean Software Development
- Lean Software Development: An Agile Toolkit
- Microsoft .NET - Architecting Applications for the Enterprise
- Test Driven Development: A Practical Guide
- Fit for developing Software: Framework for Integrated Tests
- The Art of Agile Development
Saturday, 20 June 2009
Books I currently flip through #6
Thursday, 18 June 2009
XPath
I know it's probably smoother with Linq to Xml but my project had to compile under VS2005 so I used the .NET 2.0 library which does not contain Linq but contains XPath.
Starting from the following xml file:
<pigs>
<piggy infected="false" name="bob"/>
<piggy infected="false" name="alfred"/>
<piggy infected="true" name ="rodrigo">
<disease name="swine flu"/>
<disease name="boredom"/>
<disease name="pig blues"/>
<address>confidential</address>
<phonenumber>01234546576</phonenumber>
</piggy>
</pigs>
To load the XML in memory:
XmlDocument doc = new XmlDocument();
try
{
doc.Load("piggy.xml");
}
catch (XmlException e)
{
Console.WriteLine("Could not load the file. Detail: " + e.Message);
}
To query elements based on their name:
XmlNodeList allPigs = doc.SelectNodes("/pigs/piggy"); // Returns all nodes called 'piggy' located inside the root-level node called 'pigs'.
foreach (XmlNode node in allPigs)
Console.WriteLine(node.Name + " " + node.Attributes["name"].Value);
To query elements based on their attribute name:
// Returns only infected pigs
XmlNodeList infectedPigs = doc.SelectNodes("/pigs/piggy[@infected='true']");
foreach (XmlNode node in infectedPigs)
Console.WriteLine(node.Name + " " + node.Attributes["name"].Value);
To return a single node (same query as above but only one node is expected):
// Returns the single infected pig
XmlNode infectedPig = doc.SelectSingleNode("/pigs/piggy[@infected='true']");
if (infectedPig != null)
Console.WriteLine(infectedPig.Name + " " + infectedPig.Attributes["name"].Value);
To do a query relative to the current node:
All queries above were made relative to the top of the document. But it you call SelectNodes against an XmlNode, you can do a query relative to that node. Just ommit the '/':
// Query relative to the current node. Returns all diseases for the infected pig
XmlNodeList diseases = infectedPig.SelectNodes("disease");
foreach (XmlNode node in diseases)
Console.WriteLine(node.Name + " " + node.Attributes["name"].Value);
Resources:
MSDN: XPath Syntax
LINQ to XML queries
XML Support in SQL Server 2005
Monday, 1 June 2009
Webforms vs MVC (London .NET User Group)
- Webforms has a tendency to hide HTML and actually generates a lot of goo.
- MVC relies on you knowing HTML but once you learn it, things get pretty easy.
- Webform's page lifecycle is complex
- Webforms is for morons.
- MVC is too complicated,
- Webforms has a lot of ready-made controls, lots of 3rd party vendors
- Uses a familiar event model
- MVC is for hippies.