Tuesday, March 29, 2011

How to get nested tags using Linq To XML query

Let's say we have the next XML:


This is a link example


  
    
      
        Text...
        Text...
        text...
        Text...
        Text...
      
      
        Text
        Text
        Text
      
      
        Info
        Info
        Info
        Info
      
    
  


And you want to get the tags inside on the chapter number two.
You can use this code:
// Load the document
XDocument loadedData = XDocument.Load("kjv.xml");

// Get the testament
IEnumerable<xelement> xmlTestament = loadedData.Descendants("testament").Where(c => ((string)c.Attribute("name")).Equals("New"));

// Get the book
IEnumerable<xelement> xmlBook      = xmlTestament.Descendants("book").Where(c => ((string)c.Attribute("name")).Equals("Matthew"));

// Get the chapter
IEnumerable<xelement> xmlChapter = xmlBook.Descendants("chapter").Where(c => ((string)c.Attribute("number")).Equals("2"));

foreach (string s in xmlChapter.Descendants("verse"))
{
  listBox1.Items.Add(s);
}

// -----------------------------------------------------------------------------------------


This is another way to get the info needed
//
// Load the document
XDocument loadedData = XDocument.Load("kjv.xml");

// Get the info
IEnumerable<XElement> data1 = from query in loadedData.Descendants("testament")
                                             where (string)query.Attribute("name").Value == "New"
                                        from book in loadedData.Descendants("book")
                                             where (string)book.Attribute("name").Value == "Matthew"
                                        from chap in loadedData.Descendants("chapter")
                                             where (string)chap.Attribute("number").Value == "2"
                                        select chap;

foreach (string s in data1.Descendants("verse"))
{
   listBox1.Items.Add(s);
}


//-----------------------------------------------------------------------------------


Offline command hangs when I try to take database offline

Before you take a database offline be sure there are no users / cnnections / or even SQL managment studio connected because you cannot take a database offline until there are no outstanding connections.

You can use the next command before setting it offline:
alter database DB_NAME  set restricted_user with rollback immediate

This will terminiate user connections and rollback their transactions and only allow priviledged users to connect.

Friday, March 11, 2011

VS debugger comes up, may stop on a break, but quickly stop

If the debugger sometimes comes up, may stop on a break, but quickly stops, and the asp.net web page continues running, but the IDE is returned from a debug state to an edit state, the problem is that if script debugging is enabled on IE, your debug state will stop when a popup window is opened. Turning this option off inside internet explorer advanced options makes everything work again.

To Disable Script Debugging in Internet Explorer
1.In Internet Explorer, choose Internet Options from the Tools menu.
2.In the Internet Options dialog box, click the Advanced tab.
3.On the Advanced tab, under Browsing, clear Disable Script Debugging.
4.Click OK.

Monday, March 7, 2011

How to make an image map in Expression Web

If you want to create an image map in Microsoft Expression Web follow the next steps:

  • Show the Picture tool bar on Expression Web
    • Click on View >> Toolbars >> Pictures

  • Mark the hot spot area
    • Display the image in Design mode
    • Select the image that is going to be used as a map
    • On the picture tool bar select rectangle or circle hot spot 
    • Draw the hot spot on the image
    • Type the url needed for that hot sopt


Create dynamic web template in Expression Web

If you want to create a DWT (dynamic web templates) in Microsoft Expression Web, follow the next steps:

  • Create a new document, File >> New >> Page
  • Made the modifications needed to make it look the way you need it
  • Save it as a DWT
    • Click on the main menu File >> Save As...
    • On the Save as type drop down select Dynamic Web Template
    • Click Save
  • Attach this template to an existing page
    • Click on Format >> Dynamic Web Template >> Attach Dynamic Web Template