Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Tuesday, April 9, 2013

Tips & Tricks : Visual Studio - Debugging Using Data Tips

[Data Tips] has been there from the earlier versions of Visual Studio including Visual Studio 2005 and 2008. It was greatly enhanced in Visual Studio 2010. I have noticed that many developers just don't know about this great feature in Visual Studio. This feature has been carried to Visual Studio 2012. In this post, we are going to discuss how Data Tips can improve our debugging experience. And how we can further improve it by carrying these data tips move across debugging machines enabling the debugging session experience to be shared across different team members.

If you don't know what I am talking about then just follow through this menu. Actual this option was made available for Data Tips in Visual Studio 2010. Looks familiar?? (If not, just follow this post)



Data Tips Displayed
Data Tips are displayed when we hover over the cursor on a reference while debugging when a break point is hit. The reference should be in the current scope of execution. There is a littlel + (plus) sign with the reference in case it has nested members.

[

It must be remembered that it would be showing the object assigned to reference in the current execution context. It would not show the value as it was when the line involving the data tip was executed.

Hitting Ctrl turns the data tip currently displayed nearly transparent. It becomes visible again as soon as it is released.



Data Tips & Visualizers
If there is a Visualizer loaded for the type of the reference for which the DataTips is displayed, then you should see the following icon in the Data Tip:



Since the type of policyUrl is string, Text Visualizer is displayed when we click on the icon. It would show the visualized view of the value. In this case, it is showing the text assigned to the string based reference as follows:



Clicking the drop down would let you select a different visualizer. We can even specify the default visualizer here, which would be used next time we click the visualizer icon.



Pinning Data Tips
Visual Studio 2010 introduced pinning of Data Tips. Please notice the following button on a Data Tip (when clicked this would pin it to the end of line). A pinned Data Tip can be dragged in the same document to an appropriate location.



The pins are displayed in the side bars where breakpoints and bookmarks are also displayed.



A pinned Data Tip can also be unpinned. Just click the UnPin button should do the job.



Unpinning a Data Tip turns it into a floating data tip. This is still shown on the display but with a different color. The floating data tip floats across the windows. This can be used to use data tips for members spanning across different files.



Clearing Data Tips
The data tips can be cleared for the current file. You can also clear all data tips from the debugging session.



Comments With Data Tips
We can also add comments with the Data Tips. Here we are adding the comments to an already existing data tip. It is a multi-line comment.



These comments can also be collapsed. Hovering over the button shows the tooltip. Clicking on the button collapses the data tip.



Data Tips Not In Current Context
The data tips not in the current context are still displayed. They are displayed with a Refresh button with the following tool tip.



Importing / Exporting Data Tips
The data tips can also be exported. These exported data tips can be imported back into another debuggin session even on other machines. This is specially useful to share the data tips across the team. A developer can find something while debugging and creates data tips and puts the comments at the special places. The data tips can be exported and shared with the actual developer working on the bug fix.



Here is an example of a data tip exported from one of the test project used in one of our previous posts:


Please make sure that the other developers, you are sharing it with, also has the same folder structure for the code.

Add Expressions to Data Tips
We can add more expressions to a data tip. Just right click a data tipe, following context menu should be displayed which allows us to add / remove expressions from a data tip.



We can also copy the expression and also edit value if the data tip just has a variable reference as an expression.

Make Object Id
The data tips also support making object id. Just right click the data tip and the option is available.



The Object Id can be used to observe these objects even when it is out of context. You can notice the numbered hash tag with the data tip. This is the Id created which can be used during the debugging session. Since for the new session a new object would be created so it would show that the object is not available for the next session when the same data tip is being used again.



Here we are using the same ObjectId out of the context. You can notice that it is out of context but Id is still working fine. It is used to follow up with the object during the debugging session for its life time. It is very handy to determine the memory issues with the application. The same Object Id can be used in other debugging windows including Watch window.



The same Object Id can be used in other debugging windows including Watch window.



The Object Id can also be deleted. Here we have right clicked the expression in the data tip involving the Object Id.



Deleting The Data Tips
Closing the Data tips deletes it. It would not be part of the exported xml after it is deleted.

Wednesday, February 4, 2009

XPATH for case insensitive search (translate function)

Guyz!

You know XML is case sensitive. But there are different situations when we have to deal with case insensitive search. Since XPATH is also for XML it has to be case sensitive. But can I search something in an XML document. I want my search to be case insensitive. This is because I know that my search text or pattern may be in a combination of different cases. But is there a workaround possible so that I could search an XML document for a pattern using case insensitive search.


You would be glad to know there is a way around. This is achieved using translate function in XPATH. This function is actually used to replace any combination of characters with some other combination of characters. The character in the pattern is replaced by character on the same position in the replace expression.

The syntax is as follows:

translate( text, pattern, replace expression)

Lets do an exercise. For example we have an XML element ‘MyDate’ which has information about data in the format: MM-DD-YYYY. We want to change hyphens (-) in the date to forward slashes (/). The translate function can be written like this:

translate(MyDate, ‘-’, ‘/’)

Now come to our case, what if we convert the case of our text to lower. Now we change the case of our pattern to lower. Now if we would do a search, we can do it easily. Lets write our translate function for this:

translate( MyText, ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’, ‘abcdefghijklmnopqrstuvwxyz’)

Now the first character in the pattern is ‘A’. If this is found in MyText, it would be replaced with ‘a’. The second character is ‘B”, when found, it would be replaced with second character in MyText. This would be same for every character in the pattern string.

Now you must be thinking if the length of pattern is greater than replace expression. In that case all those positions in the pattern expression which have no character in the corresponding positions in the replace expression, are just removed from MyText. So if we want to remove all hypens from our date, we would use translate function like this:

Translate(MyDate, ‘-’, ‘’)

And our XPATH expression might be like this:

//MyXMLElement[translate(@MyDate, ‘-’, ‘’) = ‘12022009’]

If you want to test your XPATH expressions, then there is an excellent online free tool. This link is as follows:

XPATH Online tool