版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、<p> XML - 報(bào)表數(shù)據(jù)的新大陸 </p><p> 隨著B(niǎo)/S系統(tǒng)的普及和XML技術(shù)的深入應(yīng)用,越來(lái)越多的數(shù)據(jù)包裹著XML的外衣被存儲(chǔ)和扔來(lái)扔去。這些數(shù)據(jù)很多源自數(shù)據(jù)庫(kù),但經(jīng)過(guò)一定的處理,數(shù)據(jù)更精簡(jiǎn),更貼近應(yīng)用。如果報(bào)表工具能利用這些XML數(shù)據(jù),則可以減少數(shù)據(jù)庫(kù)查詢和報(bào)表數(shù)據(jù)運(yùn)算操作,因?yàn)檫@些XML數(shù)據(jù)的始作俑者已經(jīng)完成了這些操作。因此說(shuō)XML是報(bào)表數(shù)據(jù)的新大陸。</p>&l
2、t;p> 傳統(tǒng)的報(bào)表工具都是只能處理關(guān)系型數(shù)據(jù)庫(kù),基本上不能處理其他數(shù)據(jù)。隨著時(shí)代的發(fā)展,一些報(bào)表工具加上了處理XML文檔的能力,但需要編程,編寫并配置插件,如此報(bào)表程序結(jié)構(gòu)復(fù)雜,接口眾多,用戶還需要根據(jù)各種規(guī)范動(dòng)手編寫程序,若XML文檔格式有很多種,就需要編寫很多種的插件,報(bào)表開(kāi)發(fā)量不小。</p><p> 如果實(shí)現(xiàn)了一種能處理XML文檔,從中獲得報(bào)表數(shù)據(jù)的通用方法。則在定制報(bào)表模板的時(shí)候就教育報(bào)表引
3、擎如何從XML文檔獲得數(shù)據(jù),則對(duì)于所有的或大部分的XML文檔無(wú)需編程,可減少報(bào)表開(kāi)發(fā)量。</p><p> 那么如何通用的處理具有復(fù)雜樹(shù)狀結(jié)構(gòu)的XML文檔呢?</p><p> 大家知道,處理XML文檔有兩種模式,一個(gè)是DOM方式,另一個(gè)是流模式。DOM方式處理方便,但速度慢耗內(nèi)存,流模式處理速度快,省內(nèi)存但使用不方便。對(duì)于.NET平臺(tái),使用System.Xml.XmlDocument
4、對(duì)象來(lái)使用DOM方式處理XML文檔,而使用XmlReader 來(lái)使用流模式處理XML文檔。</p><p> W3C國(guó)際標(biāo)準(zhǔn)組織設(shè)計(jì)XML文檔的目標(biāo)是方便的存儲(chǔ)和交換小型數(shù)據(jù)包,而不考慮數(shù)據(jù)的冗余。因此若實(shí)際系統(tǒng)中出現(xiàn)巨大的XML文檔,則大多數(shù)情況下可以認(rèn)為是不恰當(dāng)?shù)氖褂肵ML技術(shù)。因此我認(rèn)為報(bào)表工具不應(yīng)當(dāng)處理巨大的XML文檔,在此前提下,為了實(shí)現(xiàn)方便,采用DOM方式來(lái)處理XML文檔。</p>&
5、lt;p> 在.NET中使用XmlDocument加載一個(gè)XML文檔后,會(huì)形成一個(gè)以XmlDocument為根節(jié)點(diǎn)的XML對(duì)象樹(shù)狀結(jié)構(gòu),面對(duì)這個(gè)XML樹(shù)結(jié)構(gòu),獲取其中的數(shù)據(jù)方法很自然的就是使用XPath技術(shù)了。XPath技術(shù)就是在XML樹(shù)狀結(jié)構(gòu)中,以某個(gè)節(jié)點(diǎn)作為起始節(jié)點(diǎn),使用特定的描述表示的路徑移動(dòng)到其他的節(jié)點(diǎn),一般的是向其下層節(jié)點(diǎn)移動(dòng),比如移動(dòng)到某個(gè)子節(jié)點(diǎn)或?qū)O節(jié)點(diǎn),移動(dòng)到某個(gè)屬性等等。</p><p>
6、 傳統(tǒng)的報(bào)表數(shù)據(jù)源模型是兩層的,即使擴(kuò)展到可以處理XML文檔也只能處理一次,既從根節(jié)點(diǎn)出發(fā),使用某個(gè)XPath 獲得字段的值。如此只能處理一次,處理完畢后XML就被扔掉了。但很多時(shí)候需要對(duì)XML文檔進(jìn)行進(jìn)一步處理。此時(shí)傳統(tǒng)的兩層報(bào)表數(shù)據(jù)源模型是不夠的。</p><p> 為了能對(duì)XML文檔進(jìn)行精耕細(xì)作,需要從傳統(tǒng)的兩層數(shù)據(jù)源結(jié)構(gòu)突破到多層的報(bào)表數(shù)據(jù)源模型。在多層數(shù)據(jù)源節(jié)點(diǎn)中,每一個(gè)節(jié)點(diǎn)都映射到XML文檔中的某
7、個(gè)節(jié)點(diǎn),而它的子節(jié)點(diǎn)則使用XPath路徑映射到XML中的其他節(jié)點(diǎn)。如此遞歸循環(huán)后則多層的數(shù)據(jù)源可以映射到XML文檔中的任意節(jié)點(diǎn)。多層數(shù)據(jù)源模型實(shí)際上就是一個(gè)數(shù)據(jù)源樹(shù),因此處理XML文檔也就是將兩顆樹(shù)在某些節(jié)點(diǎn)上釘在一起,而XPath就是釘子。因此需要注意各級(jí)數(shù)據(jù)源節(jié)點(diǎn)的XPath配置的連續(xù)性,若一個(gè)數(shù)據(jù)源節(jié)點(diǎn)的XPath設(shè)置不對(duì),就像它釘錯(cuò)了XML節(jié)點(diǎn)或者干脆釘在空處。則它本身和所有的子孫節(jié)點(diǎn)都都會(huì)綁定落空的。</p>&
8、lt;p> 在實(shí)際應(yīng)用中,由于XML文檔不是專門為報(bào)表而產(chǎn)生的,因此報(bào)表工具還可能要離開(kāi)XML文檔來(lái)獲取更多的報(bào)表數(shù)據(jù),此時(shí)可能需要從XML文檔跳到其他XML文檔,或者返回?cái)?shù)據(jù)庫(kù)繼續(xù)執(zhí)行SQL查詢。這就非常考驗(yàn)報(bào)表數(shù)據(jù)源模型的靈活性了。</p><p> 大家都知道RSS文檔是一種XML文檔,在這里使用博客園的RSS文檔為例子說(shuō)明從XML讀取報(bào)表數(shù)據(jù)的過(guò)程。首先考察一下RSS文檔的結(jié)構(gòu),博客園首頁(yè)的RS
9、S文檔URL為 http://www.cnblogs.com/rss.aspx ,根節(jié)點(diǎn)為 rss , 然后有個(gè) channel 子節(jié)點(diǎn),下面包含了RSS文檔的基本信息,然后有若干個(gè)item節(jié)點(diǎn),列出了所有文章的基本信息。item節(jié)點(diǎn)下面是文章的基本信息,其中 wfw:commentRss 子節(jié)點(diǎn)的內(nèi)容是針對(duì)該文章回帖信息RSS文檔的URL。可以根據(jù)這個(gè)URL加載的回帖信息RSS文檔,根據(jù)RSS文檔結(jié)構(gòu)可以定義出如下的報(bào)表數(shù)據(jù)源和RSS
10、文檔的映射關(guān)系。(源碼網(wǎng)整理:www.codepub.com)</p><p> 這里的RSSXML文檔有三層結(jié)構(gòu),而且需要?jiǎng)討B(tài)加載XML文檔進(jìn)行更深入的處理,因此傳統(tǒng)的兩層結(jié)構(gòu)是肯定不夠的,必須采用多層次的報(bào)表數(shù)據(jù)源結(jié)構(gòu)。其過(guò)程是相當(dāng)復(fù)雜的,步驟為</p><p> 加載 http://www.cnblogs.com/rss.aspx 處的XML文檔,作為主XML文檔,生成一個(gè)Sys
11、tem.Xml.XmlDocument 對(duì)象,并以該XML文檔對(duì)象作為處理的出發(fā)點(diǎn)。 </p><p> 使用XPath"rss"遍歷所有符合該路徑的XML節(jié)點(diǎn),很顯然只處理了一個(gè)節(jié)點(diǎn),此時(shí)當(dāng)前位置就移動(dòng)到rss節(jié)點(diǎn)。 </p><p> 從當(dāng)前節(jié)點(diǎn)處使用XPath"channel/title"獲得網(wǎng)站標(biāo)題,使用"channel/lin
12、k"獲得網(wǎng)站地址,"channel/description"獲得網(wǎng)站說(shuō)明,"channel/pubDate"獲得文檔發(fā)布時(shí)間。 </p><p> 從當(dāng)前節(jié)點(diǎn)處使用"channel"遍歷所有符合該路徑的XML節(jié)點(diǎn),很顯然只處理了一個(gè)節(jié)點(diǎn),此時(shí)當(dāng)前位置就移動(dòng)到了"channel"節(jié)點(diǎn)。 </p><p&g
13、t; 變量當(dāng)前節(jié)點(diǎn)下的所有的item子節(jié)點(diǎn),并依次設(shè)置為當(dāng)前節(jié)點(diǎn)。 </p><p> 從當(dāng)前節(jié)點(diǎn)處使用“title"獲得文章標(biāo)題,使用"link"獲得文章地址,使用”author"獲得作者,“pubDate"獲得發(fā)布時(shí)間,"description"獲得文章內(nèi)容,"slash:comment"獲得回復(fù)數(shù),“wfw:com
14、mentRss"獲得回復(fù)RSSXML文檔的URL。 </p><p> 當(dāng)處理"wfw:commentRss"節(jié)點(diǎn)時(shí),程序根據(jù)某個(gè)特定的設(shè)置加載該節(jié)點(diǎn)數(shù)據(jù)指向的XML文檔,也就是加載針對(duì)當(dāng)前文章的回復(fù)RSSXML文檔。并遍歷剛剛加載的XML文檔的所有符合"rss/channel/item"的節(jié)點(diǎn),并依次設(shè)置為當(dāng)前節(jié)點(diǎn)。 </p><p>
15、 從當(dāng)前節(jié)點(diǎn)處,使用"author"獲得回復(fù)作者,使用”pubDate"獲得回復(fù)時(shí)間,使用"description"獲得回復(fù)內(nèi)容。 </p><p> 由于RSSXML文檔中的description節(jié)點(diǎn)處保存的時(shí)HTML代碼,因此還需要解析HTML代碼并提取其中的純文本內(nèi)容。 </p><p> 從上面的步驟可以看出,數(shù)據(jù)源結(jié)構(gòu)中的每
16、一個(gè)節(jié)點(diǎn)都釘?shù)搅薠ML文檔中的某個(gè)節(jié)點(diǎn),而且在回復(fù)列表這個(gè)節(jié)點(diǎn)中,程序執(zhí)行了XML文檔的跳轉(zhuǎn),從主XML文檔跳到回復(fù)RSSXML文檔,而且是處理樹(shù)狀結(jié)構(gòu)的,因此是遞歸操作,很多狀態(tài)信息都由系統(tǒng)調(diào)用堆棧自動(dòng)保存,無(wú)需程序自己保存了。</p><p> 如果報(bào)表程序能直接連接到博客園數(shù)據(jù)庫(kù)的話,還可以從文章作者這個(gè)節(jié)點(diǎn)執(zhí)行XML文檔到數(shù)據(jù)庫(kù)的跳轉(zhuǎn),直接查詢數(shù)據(jù)庫(kù),獲得文章作者的一些注冊(cè)信息。實(shí)事上,這個(gè)數(shù)據(jù)源樹(shù)狀結(jié)
17、構(gòu)中每一個(gè)節(jié)點(diǎn)都可以發(fā)生XML到XML,XML到數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù)到XML的三種跳轉(zhuǎn),這大大擴(kuò)展了獲取報(bào)表數(shù)據(jù)的靈活性。</p><p> 如果一個(gè)信息系統(tǒng)是純XML應(yīng)用的話,則報(bào)表工具就可以在眾多的XML文檔中跳躍著采集數(shù)據(jù)而不需要查詢數(shù)據(jù)庫(kù),就像少林寺的武僧在梅花樁上打架而不用碰地,因此也就不用管下面是JAVA土壤的還是.NET土壤。此時(shí)所有的數(shù)據(jù)庫(kù)操作,業(yè)務(wù)邏輯等等都運(yùn)行在后臺(tái),而報(bào)表工具無(wú)需關(guān)心,只要系統(tǒng)底
18、層安全可靠,則報(bào)表模塊也就安全可靠,系統(tǒng)底層無(wú)論如何修改,只要XML文檔格式不變則報(bào)表模塊就不需要修改。對(duì)于非常復(fù)雜的報(bào)表數(shù)據(jù)源,超出了報(bào)表工具的定制能力,則可以編程提供一個(gè)XML文檔供報(bào)表程序使用。以前系統(tǒng)是直接通過(guò)API向報(bào)表程序提供復(fù)雜報(bào)表數(shù)據(jù),而現(xiàn)在通過(guò)XML文檔以“隔山打?!钡姆绞较驁?bào)表程序提供復(fù)雜報(bào)表數(shù)據(jù)。此時(shí)系統(tǒng)結(jié)構(gòu)更安全,邊界更清楚,體現(xiàn)了XML WebService的指導(dǎo)思想。這種獲取數(shù)據(jù)的思想可以不局限于報(bào)表數(shù)據(jù)的獲
19、取,還可以應(yīng)用到其他領(lǐng)域。</p><p> 以上討論的應(yīng)用系統(tǒng)限于B/S系統(tǒng),但可以設(shè)想,C/S系統(tǒng)經(jīng)過(guò)改造,可以通過(guò)某種方式向報(bào)表工具提供XML數(shù)據(jù)文檔。</p><p> 從上面的討論可以看出,XML確實(shí)是報(bào)表數(shù)據(jù)的新大陸,本人寫的報(bào)表工具已經(jīng)初步體現(xiàn)了這種思想。但這種思想可能有點(diǎn)激進(jìn),還不成熟不完善,希望大家多多指點(diǎn)。</p><p><b>
20、 XML源文件:</b></p><p> <?xml version="1.0" encoding="utf-8" standalone="yes" ?> </p><p> - <rss version="2.0" xmlns:dc="http://purl.o
21、rg/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/sla
22、sh/"></p><p> - <channel></p><p> <title>博客園-首頁(yè)原創(chuàng)精華區(qū)</title> </p><p> <link>http://www.cnblogs.com/</link> </p><p> <descri
23、ption>技術(shù)改變世界</description> </p><p> <language>zh-cn</language> </p><p> <lastBuildDate>Mon, 07 Jun 2010 12:57:20 GMT</lastBuildDate> </p><p> <
24、;pubDate>Mon, 07 Jun 2010 12:57:20 GMT</pubDate> </p><p> <ttl>60</ttl> </p><p><b> - <item></b></p><p> <title>網(wǎng)站管理藝術(shù)</title>
25、</p><p> <link>http://www.cnblogs.com/Nobel/archive/2010/06/07/1753464.html</link> </p><p> <dc:creator>諾貝爾</dc:creator> </p><p> <author>諾貝爾</au
26、thor> </p><p> <pubDate>Mon, 07 Jun 2010 12:56:00 GMT</pubDate> </p><p> <guid>http://www.cnblogs.com/Nobel/archive/2010/06/07/1753464.html</guid> </p><p&
27、gt; - <description></p><p> - <![CDATA[ </p><p> <p>閱讀: 0 評(píng)論: 0 作者: <a href="http://www.cnblogs.com/Nobel/" target="_blank">諾貝爾</a> 發(fā)表于 2010-06-
28、07 20:56 <a href="http://www.cnblogs.com/Nobel/archive/2010/06/07/1753464.html" target="_blank">原文鏈接</a></p><p>做人的藝術(shù)是:人不犯我,我不犯人,人若犯我,我必犯人!</p> <p>做網(wǎng)站也要有藝術(shù),雖然我沒(méi)怎么做過(guò)
29、網(wǎng)站的管理員,不過(guò)我也曾經(jīng)做過(guò)某個(gè)不足100人的論壇的管理員,偶爾還能得到一點(diǎn)管理上面的心得。</p> <p>下面說(shuō)說(shuō),大家討論一下:</p> <p>一、犯賤者的應(yīng)對(duì)方式:</p> <p>比如謾罵之類的,一開(kāi)始很害怕刪掉會(huì)影響人氣,也害怕這樣會(huì)顯得自己不夠大度,但是后來(lái)的經(jīng)驗(yàn)總結(jié),對(duì)于這種是要堅(jiān)決地抵制的。你不可能要求所有人都愛(ài)你,容忍是有限度,也必須要有限度
30、。雖然放棄了這些客戶,但是也應(yīng)該看到這樣是有助改善現(xiàn)有用戶的用戶體驗(yàn)和用戶環(huán)境的,從這點(diǎn)上看,其實(shí)利大于弊。在商業(yè)</p><p><b> ]]> </b></p><p> </description></p><p><b> </item></b></p><
31、p><b> - <item></b></p><p> <title>How does ElementName Binding work – Part 2 BindingExpression</title> </p><p> <link>http://www.cnblogs.com/idior/archi
32、ve/2010/06/07/1753452.html</link> </p><p> <dc:creator>idior</dc:creator> </p><p> <author>idior</author> </p><p> <pubDate>Mon, 07 Jun 2010 1
33、2:28:00 GMT</pubDate> </p><p> <guid>http://www.cnblogs.com/idior/archive/2010/06/07/1753452.html</guid> </p><p> - <description></p><p> - <![CDATA[ &
34、lt;/p><p> <p>閱讀: 27 評(píng)論: 0 作者: <a href="http://www.cnblogs.com/idior/" target="_blank">idior</a> 發(fā)表于 2010-06-07 20:28 <a href="http://www.cnblogs.com/idior/archive
35、/2010/06/07/1753452.html" target="_blank">原文鏈接</a></p><p>In <a href="http://www.cnblogs.com/idior/archive/2010/05/28/1746513.html" target="_blank">part 1</
36、a>, I gave a general finding rule for ElementName binding, it works in most cases, however there are some cases you cannot explain them with the general rule. I will cover some of them in the f</p><p> &
37、amp;lt;</span><span style="color: #a31515">local</span><span style="color: blue">:</span><span style="color: #a31515">CustomControl1</span><span
38、style="color: blue">/></span></pre><pre class="code"><span style="color: blue"> </</span><span style="color: #a31515">Window
39、</span><span style="color: blue">></span></pre><pre class="code"><span style="color: blue"><br /></span></pre><pre class="
40、;code"> <span style="color: blue"><</span><span style="color: #a31515">Style </span><span style</p><p> <</span><span style=&
41、quot;color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">="Template"></p><p> <</sp
42、an><span style="color: #a31515">Setter.Value</span><span style="color: blue">></p><p> <</span><span style="color: #a31515">Contr
43、olTemplate </span><span style="color: red">TargetType</span><span style="color: blue">="{</span><span style="color: #a31515">x</span><span s
44、tyle="color: blue">:</span><span style="color: #a31515">Type </span><span style="color: red">local</span><span style="color: blue">:</span
45、><span style="color: red">CustomControl1</span><span style="color: blue">}"></p><p> <</span><span style="color: #a31515">St
46、ackPanel</span><span style="color: blue">></p><p> <</span><span style="color: #a31515">Button </span><span style="color: red; backgro
47、und-color: yellow; "><strong>Name</strong></span><span style="color: blue; background-color: yellow; "><strong>="btn"</strong></span><span style=&q
48、uot;color: blue"> </span><span style="color: red">Content</span><span style="color: blue">="PFS Button"/></p><p> <</span>&l
49、t;span style="color: #a31515">TextBlock </span><span style="color: red">Name</span><span style="color: blue">="tbk" /></p><p> &
50、lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: blue">></p><p> <</span><span style="color: #a31515"
51、>ControlTemplate.Triggers</span><span style="color: blue">></p><p> <</span><span style="color: #a31515">DataTrigger </span><span style=
52、"color: red">Binding</span><span style="color: blue">="{</span><span style="color: #a31515">Binding </span><span style="color: red; background-c
53、olor: yellow; "><strong>ElementName</strong></span><span style="color: blue; background-color: yellow; "><strong>=btn</strong></span><span style="color:
54、 blue">, </p><p> </span><span style="color: red">Path</span><span style="color: blue">=Content}" </p><p> </span>
55、;<span style="color: red">Value</span><span style="color: blue">="PFS Button"></p><p> <</span><span style="color: #a31515"&g
56、t;Setter </span><span style="color: red">TargetName</span><span style="color: blue">="tbk" </p><p> </span><span style="color: red"&g
57、t;Property</span><span style="color: blue">="Text" </p><p> </span><span style="color: red">Value</span><span style="color: blue">
58、="PFS TextBlock"/></p><p> </</span><span style="color: #a31515">DataTrigger</span><span style="color: blue">></p><p>
59、 </</span><span style="color: #a31515">ControlTemplate.Triggers</span><span style="color: blue">></p><p> </</span><span style=&quo
60、t;color: #a31515">ControlTemplate</span><span style="color: blue">></p><p> </</span><span style="color: #a31515">Setter.Value</span>&
61、lt;span style="color: blue">></p><p> </</span><span style="color: #a31515">Setter</span><span style="color: blue">></p>
62、<p> </</span><span style="color: #a31515">Style</span><span style="color: blue">></p><p> </span></pre></p><p> <
63、;p> </p></p><p> <p>Let’s go back to our rules first:</p></p><p><b> <ol></b></p><p> <li>Start from the element w
64、hich applied the ElementName Binding, keep searching on the logic tree via its logic parent, until an element which has NameScope is found, let’s call it NameScopeElement. If no element owns a NameScope, search
65、 will stop. </p><p> </li><li>Call the NameScope.FindName method on the found NameScope. </p><p> </li><li>If the element is found, return it, otherwise try to get the
66、template parent of NameScopeElement; if the template parent is null, it will stop search. or it goes back to step 1, search on the logic tree for element owns a NameScope.</li></ol></p><p> <
67、p>If we start from DataTrigger, you will find its logic parent would be null, the search will not continue. Ok, I have to acknowledge the original statement is oversimplified. </p></p><p>
68、 <p><strong>It actually starts form the TargetElement of the BindingExpression which is created by the ElementName Binding.</strong> Here it is the <span style="color: red">CustomContro
69、l1</span>. A little confused here? Let’s see what’s the BindingExpression and what’s the relationship between a BindingExpression and Binding.</p></p><p>
70、 <p><a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.aspx" target="_blank">Binding</a> class is the high-level class for the declaration of a binding; the
71、 <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.aspx" target="_blank">Binding</a> class provides many properties that allow you to specify the characteristics
72、 of a binding. A related class,<a href="http://msdn.microsoft.com/en-us/library/system.windows.data.bindingexpression.aspx" target=</p><p> <p>In most cases, the TargetElement of the Bind
73、ingExpression will be the DependencyObject whose DependencyProperty is set to a Binding MarkupExtension. For example, the TargetElement of the BindingExpression will be set to the Button object in following codes:</p&
74、gt;<pre class="code"><span style="color: blue"><</span><span style="color: #a31515">Button </span><span style="color: red">Content</sp
75、an><span style="color: blue">="{</span><span style="color: #a31515">Binding </span><span style="color:</p><p> </span></pre><a href
76、="http://11011.net/software/vspaste" target="_blank"></a></p><p> <p> </p></p><p> <p>However our style of CustomControl1, DataTrigger i
77、s not a DependencyObject and Binding property is not a DependencyProperty either.</p><pre class="code"><span style="color: blue"><</span><span style="color: #a31
78、515">DataTrigger </span><span style="color: red">Binding</span><span style="color: blue">="{</span><span style="color: #a31515">Binding </
79、span><span style="color: red">ElementName</span><span style="color: blue">=btn, </span><span style="color: red">Path</span><span style="color:
80、bl</p><p> </span><span style="color: red">Value</span><span style="color: blue">="PFS Button"></span></pre></p><p> &l
81、t;p>The BindingExpression will be created in a different way than others, it’s created in StyleHelper.GetDataTriggerValue methods which are internal to the WPF framework. In that method, the BindingExpressio
82、n’s TargetElement will be set to the object which applies the style that defines the DataTrigger.</p></p><p> <p>Ok. We are clear of where should we start the search, let’s c
83、ontinue our search. CustomControl1 doesn’t own a NameScope, so we will get his parent which is Window, since Window has a NameScope, we will call the FindName method on Window’s NameScope, but we stil
84、l cannot find btn. As I said both Window and ControlTemplate have their own NameScope, btn is registered in ControlTemplate’s NameScope rather than Window, so you cannot find btn in Window’s NameScope
85、. </p></p><p> <p>But if you run the above code, you will see it works. Ok, there is another point i missed in part 1.</p></p><p> <p>When we start the search from the
86、TargetElement of the BindingExpression,<strong> it will check ResolveNamesInTemplate property of the BindingExpression</strong>, if it’s true, it will try to find the element defined in it
87、s template first. In our case, the BindingExpression is created from a DataTrigger, the ResolveNamesInTemplate is set to true in StyleHelper.GetDataTriggerValue method, now btn can be found.</p></p><p>
88、; <p>Let’s revised the finding rule:</p></p><p><b> <ol></b></p><p> <li>Get the BindingExpression which is created by the ElementName Binding.&l
89、t;/p><p> </li><li>Start from the TargetElement of the BindingExpression. If the value of BindingExpression’s ResolveNamesInTemplate property is true, it will search in the TargetElement&
90、amp;#8217;s template, if an element with the same name can be found in its template then return it, else go to next step.</p><p> </li><li>Keep searching on the logic tree via its logic parent,
91、until an element which has NameScope is found, let’s call it NameScopeElement. If no element owns a NameScope, search will stop. </p><p> </li><li>Call the NameScope.FindName method on
92、 the found NameScope. </p><p> </li><li>If the element is found, return it, otherwise try to get the template parent of NameScopeElement; if the template parent is null, it will stop search. or
93、it goes back to step 3, search on the logic tree for an element owns a NameScope.</li></ol><div>In part 3, I will give some introduction to InheritanceContext which is also called LogicalParent 2.0. :)&
94、lt;/div><img src="http://www.cnblogs.com/idior/aggbug/1753452.html?type=1" width="1" height="1" alt=""/><p>評(píng)論: 0 <a href="http://www.cnblo</p><p&g
95、t;<b> ]]> </b></p><p> </description></p><p><b> </item></b></p><p><b> - <item></b></p><p> <title>
96、提高Windows 產(chǎn)品密鑰安全性</title> </p><p> <link>http://www.cnblogs.com/gnielee/archive/2010/06/07/fetch-productkey-via-csharp.html</link> </p><p> <dc:creator>Gnie</dc:crea
97、tor> </p><p> <author>Gnie</author> </p><p> <pubDate>Mon, 07 Jun 2010 12:13:00 GMT</pubDate> </p><p> <guid>http://www.cnblogs.com/gnielee/archi
98、ve/2010/06/07/fetch-productkey-via-csharp.html</guid> </p><p> - <description></p><p> - <![CDATA[ </p><p> <p>閱讀: 71 評(píng)論: 2 作者: <a href="http://www.c
99、nblogs.com/gnielee/" target="_blank">Gnie</a> 發(fā)表于 2010-06-07 20:13 <a href="http://www.cnblogs.com/gnielee/archive/2010/06/07/fetch-productkey-via-csharp.html" target="_blank&quo
100、t;>原文鏈接</a></p><p>     今天無(wú)意中在CodePlex 發(fā)現(xiàn)一個(gè)叫<a href="http://wpkf.codeplex.com/" target="_blank">Windows Product Key Finder</a> 的項(xiàng)目,從
101、名字就可以看出它的用途。通過(guò)這款軟件可以輕松的獲取本地Windows 的產(chǎn)品密鑰。當(dāng)然對(duì)于找不到密鑰光盤的人來(lái)說(shuō)這當(dāng)然是款實(shí)用的工具,但如果到了某些圖謀不軌的人手里那您的產(chǎn)品密鑰必定要受到威脅。</p> <p>     閱讀了項(xiàng)</p><p><b> {</b></p>&l
102、t;p> <span style="color: green">// Offset of first byte of encoded product key in </p><p> // 'DigitalProductIdxxx" REG_BINARY value. Offset = 34H.</p><p> <
103、;/span><span style="color: blue">const int </span>keyStartIndex = 52;</p><p> <span style="color: green">// Offset of last byte of encoded product key in </p>
104、<p> // 'DigitalProductIdxxx" REG_BINARY value. Offset = 43H.</p><p> </span><span style="color: blue">const int </span>keyEndIndex = keyStartIndex + 15;</
105、p><p> <span style="color: green">// Possible alpha-numeric characters in product key.</p><p> </span><span style="color: blue">char</span>[] digits =
106、<span style="color: blue">new char</span>[]</p><p><b> {</b></p><p> <span style="color: #a31515">'B'</span>, <span style=&qu
107、ot;color: #a31515">'C'</span>, <span style="color: #a31515">'D'</span>, <span style="color: #a31515">'F'</span>, <span style="colo
108、r: #a31515">'G'</span>, <span style="color: #a31515">'H'</span>, <span style="color: #a31515">'J'</span>, <span style="color: #a31
109、515">'K'</span>, <span style="color: #a31515">'M'</span>, <span style="color: #a31515">'P'</span>, <span style="color: #a31515&quo
110、t;>'Q'</span>, <span style="color: #a31515">'R'</span>, </p><p> <span style="color: #a31515">'T'</span>, <span style="co
111、lor: #a31515">'V'</span>, <span style="color: #a31515">'W'</span>, <span style="color: #a31515">'X'</span>, <span style="color: #a
112、31515">'Y'</span>, <span style="color: #a31515">'2'</span>, <span style="color: #a31515">'3'</span>, <span style="color: #a31515&q
113、uot;>'4'</span>, <span style="color: #a31515">'6'</span>, <span style="color: #a31515">'7'</span>, <span style="color: #a31515">
114、;'8'</span>, <span style="color: #a31515">'9'</span>,</p><p><b> };</b></p><p> <span style="color: green">// Length of
115、decoded product key</p><p> </span><span style="color: blue">const int </span>decodeLength = 29;</p><p> <span style="color: green">// Length of dec
116、oded product key in byte-form.</p><p> // Each byte represents 2 chars.</p><p> </span><span style="color: blue">const int </span>decodeStringLength = 15;</p>
117、<p> <span style="color: green">// Array of containing the decoded product key.</p><p> </span><span style="color: blue">char</span>[] decodedChars = <
118、span style="color: blue">new char</span>[decodeLength];</p><p> <span style="color: green">// Extract byte 52 to 67 inclusive.</p><p> </span><span
119、style="color: #2b91af">ArrayList </span>hexPid = <span style="color: blue">new </span><span style="color: #2b91af">ArrayList</span>();</p><p>
120、<span style="color: blue">for </span>(<span style="color: blue">int </span>i = keyStartIndex; i <= keyEndIndex; i++)</p><p><b> {</b></p>
121、<p> hexPid.Add(digitalProductId[i]);</p><p><b> }</b></p><p> <span style="color: blue">for </span>(<span style="color: blue">int <
122、;/span>i = decodeLength - 1; i >= 0; i--)</p><p><b> {</b></p><p> <span style="color: green">// Every sixth char is a separator.</p><p> &l
123、t;/span><span style="color: blue">if </span>((i + 1) % 6 == 0)</p><p><b> {</b></p><p> decodedChars[i] = <span style="color: #a31515">'
124、;-'</span>;</p><p><b> }</b></p><p> <span style="color: blue">else</p><p><b> </span>{</b></p><p> <span
125、 style="color: green">// Do the actual decoding.</p><p> </span><span style="color: blue">int </span>digitMapIndex = 0;</p><p> <span style="co
126、lor: blue">for </span>(<span style="color: blue">int </span>j = decodeStringLength - 1; j >= 0; j--)</p><p><b> {</b></p><p> <span st
127、yle="color: blue">int </span>byteValue = (digitMapIndex << 8) | (<span style="color: blue">byte</span>)hexPid[j];</p><p> hexPid[j] = (<span style=&
128、quot;color: blue">byte</span>)(byteValue / 24);</p><p> digitMapIndex = byteValue % 24;</p><p> decodedChars[i] = digits[digitMapIndex];</p><p><b> }</b>
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫(kù)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 新大陸內(nèi)部問(wèn)責(zé)制度
- 六爻新大陸進(jìn)階講義
- 馬化騰我們發(fā)現(xiàn)了“新大陸”
- 新大陸軟件公司營(yíng)銷策略研究.pdf
- 哥倫布發(fā)現(xiàn)新大陸與鄭和下西洋比較文摘
- [教育]長(zhǎng)沙新大陸銀座項(xiàng)目廣告策略及創(chuàng)意提案
- 新大陸翼碼公司的競(jìng)爭(zhēng)戰(zhàn)略研究.pdf
- 新大陸posdownload pc端使用說(shuō)明(用usb下載程序)
- 16506.基于核基因非編碼區(qū)研究靈長(zhǎng)目舊大陸猴及新大陸猴系統(tǒng)發(fā)育關(guān)系
- 比較文化視野下的世界華裔文學(xué)新大陸:中亞?wèn)|干文學(xué)
- 應(yīng)用西班牙語(yǔ)畢業(yè)論文論哥倫布發(fā)現(xiàn)新大陸對(duì)經(jīng)濟(jì)的影響
- 應(yīng)用西班牙語(yǔ)畢業(yè)論文論哥倫布發(fā)現(xiàn)新大陸對(duì)經(jīng)濟(jì)的影響
- 比較文化視野下的世界華裔文學(xué)新大陸:中亞?wèn)|干文學(xué)_38345.pdf
- 新大陸的發(fā)現(xiàn)對(duì)十六世紀(jì)西班牙社會(huì)生活的影響.pdf
- 大陸邊緣
- 被動(dòng)大陸邊緣&活動(dòng)大陸邊緣
- 解析德沃夏克自新大陸第四樂(lè)章在雙排鍵電子琴上的編配和演奏
- 大陸的中國(guó)夢(mèng)
- 日本的大陸政策
- 大陸均勢(shì)政策
評(píng)論
0/150
提交評(píng)論