Monday, May 5, 2008

How to handle xml namespace and xpath by using Linq Xml


.Net3.5对XML的支持更进一步, 你可以彻底地抛弃Dom处理方式了. 因为XDocument和XElement以及XNode比之前的XmlDocument和XmlNode处理速度更快.



下面是一个相对较为复杂的例子, 其中展现了怎样处理Xml的Namespace以及如何使用XPath来定位一个Xml元素.



/// <summary>
/// 查找所有节点名为p:cNvPr的Xml元素
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button_SelectElementByXPath_Click(object sender, EventArgs e)
{
XDocument xDoc=XDocument.Load(@"c:slide1.xml");


//using System.Xml.XPath
// XElement或XDocument之所以有能力处理XPath, 是靠System.Xml.XPath.Extensions这个扩展static类提供的功能
// public static IEnumerable<XElement> XPathSelectElements(this XNode node, string expression, IXmlNamespaceResolver resolver)
// XPathSelectElements()函数还需要一个参数作为XML Namespace的解析器, 而XmlNamespaceManager类就是一个这样的解析器,
// 所以还需要引入System.Xml命名空间, 来创建一个XmlNamespaceManager对象

NameTable nt = new NameTable();
XmlNamespaceManager nameMgr = new XmlNamespaceManager(nt);
nameMgr.AddNamespace("p", "http://schemas.openxmlformats.org/presentationml/2006/main");

//***注意参数应该是p:cNvPr, 而不是cNvPr
var elements = from element in xDoc.XPathSelectElements("//p:cNvPr",nameMgr)
select element ;
foreach (var element in elements)
{
System.Console.Out.Write(element);
System.Console.Out.WriteLine("==============");
}

}


/// <summary>
/// 查找所有节点名为p:cNvPr的Xml元素
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button_SelectElementByDescendant_Click(object sender, EventArgs e)
{
XDocument xDoc = XDocument.Load(@"c:slide1.xml");
XNamespace xns = XNamespace.Get("http://schemas.openxmlformats.org/presentationml/2006/main");

//public IEnumerable<XElement> Descendants(XName name)

//***注意参数应该是cNvPr, 而不是p:cNvPr
var elements1 = from element in xDoc.Descendants(xns.GetName("cNvPr"))
select element ;

//因为XNamespace类重载了加法运算符号,
// 所以对一个XNamespace对象和一个localName字符串相加, 返回的是一个XName对象,
// 正是 XElement或XDocument的Descendants()函数所需要的参数类型

//下面代码返回的elements1, 和elements1是完全一样的
var elements2 = from element in xDoc.Descendants(xns + "cNvPr")
select element ;

foreach(var element in elements2)
{
System.Console.Out.Write(element) ;
System.Console.Out.WriteLine("==============");
}
}

Monday, April 28, 2008

English symbol and mark pronounce


Punctuation

apostrophe ( ' ' )
brackets ( ), [ ], { }, < >
colon ( : )
comma ( , )
dashes ( ‒ , -, -, ― )
ellipsis ( …, ... )
exclamation mark ( ! )
full stop/period ( . )
guillemets ( « » )
hyphen ( -, ‐ )
question mark ( ? )
quotation marks ( ' ', " " )
semicolon ( ; )
slash/stroke ( / )
solidus ( ∕ )

Interword separation

spaces ( ) ( ) ( )
interpunct ( · )

General typography

ampersand ( & )
asterisk ( * )
at ( @ )
backslash ( \ )
bullet ( • )
( ^ )
currency ( ¤ ) ¢, $, €, £, ¥, ₩, ₪
dagger/obelisk ( † ) ( ‡ )
degree ( ° )
inverted exclamation point ( ¡ )
inverted question mark ( ¿ )
number sign ( # )
numero sign ( № )
percent and related signs
( %, ‰, ‱ )
pilcrow ( )
prime ( ′ )
section sign ( § )
( ~ )
umlaut/diaeresis ( ¨ )
underscore/understrike ( _ )
vertical/pipe/broken bar ( |, ¦ )


Uncommon typography

asterism ( ⁂ )
index/fist ( ☞ )
therefore sign ( ∴ )
lozenge ( ◊ )
interrobang ( ‽ )
irony mark ( ؟ )
reference mark ( ※ )
sarcasm mark (+ +)

I will focus on Oracle Advanced topics

1. Indexes and Storage Types

2. Transactions and Locks

http://www.wisc.edu/drmt/oratips/sess004.html

3. Oracle and XML Integration

4. Oracle Database Extensions for .NET

5. Debugging PL/SQL
6. Tuning PL/SQL Applications

http://www.wisc.edu/drmt/oratips/sess006.html
7. Tracing PL/SQL Execution

Thursday, April 24, 2008

Idea For Event Notifier

Event Notifier

.net 架构, 为了适合其他非Windows的应用, 可以提供web service接口.

Purpose user

For developer(我将提供专门的API)

For system integriting vendor(提供一个管理界面)

像淘宝这样的公司, 比如他们需要同步几个DB server, 同步有可能出错, 这样严重的事情, 应该尽早通知相关人员, 去做出反应.

像很多软件开发公司, continous integriting fail, 就有必要通知所有的stake holders

Event source:

Window event message

Windows System Monitor

SQL Server 发邮件动作的截获

Log4J, NLog4J

ISV to call api

文件的新增, 删除和修改等动作

Event receiver

SMS

Send email

Printer

Play media

Launch other application

Instant message

Serial singal

Record the event log in talk machine

ADO.NET call oracle stored procedure

http://www.c-sharpcorner.com/UploadFile/john_charles/CallingOraclestoredproceduresfromMicrosoftdotNET06222007142805PM/CallingOraclestoredproceduresfromMicrosoftdotNET.aspx

Thursday, April 10, 2008

Today is my dear wife Birthday

今天是老婆的生日, 也是我们的第二个结婚纪念日!
祝老婆生日快乐! 祝老婆永远开心!
我会努力工作, 我们终将会过上更加幸福的日子了!
我爱你, 老婆!

Wednesday, April 2, 2008

Best Practice--.Net Performance Test

Production Debugging for .NET Framework Applications
http://msdn2.microsoft.com/en-us/library/ms954594.aspx

Performance and scalability checklist
http://msdn2.microsoft.com/en-us/library/ms998592.aspx

Performance Test guide
http://www.codeplex.com/PerfTesting

Performance Optimization and Test Best Practice Tools
http://www.codeplex.com/GuidanceExplorer