星期四, 九月 27, 2007

如何在Powershell中解析HTMLDocument

HTML document是相对XML Document而言,非格式良好的XMLnon-well formatted.
使用标准的XMLDocument会出现语法检查错误。
必须使用mshtml.dll包含的标准HTMLDocumentClass.
标准的vbscript:代码
set htmlDoc= createobject("HTMLFILE")
page = "<html><body>this is a test</body></html>"
htmlDoc.write(page)
htmlDoc.close


对应的POWSERShell代码为:
$htmlDoc= New-Object -com "HTMLFILE"
$page = "<html><body>this is a test</body></html>"
$htmlDoc.write($page) #出错代码,出现type mismatch错误.
$htmlDoc.close

具体的原因看网络上的解释,似乎是DOM包装的时候,有些接口没有实现造成的问题。
所以目前找到的方法是使用IE控件,代码如下:
$IE= New-Object -com "InternetExplorer.Application"
$IE.navigate('about:blank')##必须的代码行
$IE.Resizable=$True
$IE.StatusBar=$True
$IE.AddressBar=$False
$IE.MenuBar=$False
$IE.Toolbar=$False
while ($IE.busy)
{
sleep -milliseconds 50
}
$page = "<html><body>this is a test</body></html>"
$IE.documetn.body.innerHTML=$page#该代码在IE7以下的IE中不能工作必须换成下面的代码
$IE.document.write( $page) #或者替换为 $oIE.document.IHTMLDocument2_write($html)

出现的错误为:
Property 'innerHTML:' cannot be found on this object; make sure it exists
and is settable.

如何得到Windows所有安装的COM控件?

在PowerShell下,用一下命令都可以做到
1.gci HKLM:\Software\Classes -ea 0| ? {$_.PSChildName -match '^\w+\.\w+$' -and (gp "$($_.PSPath)\CLSID" -ea 0)} | ft PSChildName
2.get-wmiobject Win32_COMClass

星期三, 九月 26, 2007

PowerShell 特殊语法符号。@

@()

空数组

$hash = @{ }

创建空哈希表

@(Get-Alias;Get-Process)

执行其中的两条命令,然后在数组中返回结果


字符串常量:

@”

这是“here string”,其中可包含任意字符(包括回车和引号)。将计算表达式 $(2+2)

”@

@’

带单引号的“here string”不计算表达式。 ‘@

星期五, 九月 21, 2007

PowerShell 错误处理及查看DLL方法

可以在任何function或代码文件中申明如下语句:
trap [Exception]
{
write-host ("trapped " + $_.Exception.GetType().Name); continue;
}


星期四, 九月 20, 2007

Regular Express 表达删除一个空行(blank line)

程序开发中一个常见的问题是如何删除一大段文本中的空行。
所谓的空行就是一行只包含一些空格,制表符或其他不可见的符号的文本行。
在Vbscript的RegExp 对象,支持RegExpOption.Multiline的属性,可以轻易删除。
但其他各种语言,perl,vbscript等等,没有简单的方法。
regularE="^$"可以匹配一个只包含回车换行的空行
但通过十六进制来看很多文本往往发现很多包含000D 00 0D 00 0A之类的空行。
非常难以处理。

标准的删除一个包含很多回车换行的文本的规则表达为
regularE="[\r\n]+\s*[\r\n]+"
这里是一个详细的解释:

http://www.ultraedit.com/index.php?name=Forums&file=viewtopic&t=2777

但这种方法会删除一个所有的回车换行。
所以必须单独编写方法来出来。

星期三, 九月 19, 2007

Microsoft PowerShell 1,0 定制提示符号的简单技巧





















set-item -path function:prompt -value {' PS '+ $(Get-Date -format t) + " " + $(write-host -f red $(Get-Location) -nonewline) + '> '}

得到如下效果:

星期一, 九月 17, 2007

如何通过VBA来让Excel显示HTML代码?

目前发现的方法只是让 EXCEL通过web query是直接支持的。
如果需要更加灵活的方式,目前只能通过把 HTML代码复制到系统粘贴板,然后再让EXCEL
粘帖来实现。

首先在Excel里 ,按下Alt+F11打开宏编写。
然后在菜单工具-->引用。。里找到 Microsoft Forms 2.0 object library ,启用之,
然后书写一下代码,则可以实现了Excel的HTML渲染。

Dim MyDataObj As New DataObject

MyDataObj.SetText "

OneTwo
"

MyDataObj.PutInClipboard '复制到clipboard

然后再调用

ActiveSheet.Paste

则可以显示HTML效果了。

另外一种通过 HTMLProject 来完成,把HTML页面直接传送过去

ActiveWorkbook.HTMLProject.HTMLProjectItems(stockCode).Text = resl
ActiveWorkbook.HTMLProject.RefreshProject


星期五, 九月 14, 2007

几种语言如何设置跳过盗链的检查

一般Java 访问网站。
URL url=new URL("url地址");
然后
Connection conn = url.OpenConnection();
加入下面这行:
conn.addRequestProperty("REFERER", "http://www.mydomain.com");
然后后面再用conn.readLine等就可以避免盗链检查了。

命令行curl访问一个网站避免盗链检查的方式:

curl -x 191.168.1.1:1688 -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -D cookie0001.txt --proxytunnel -o test.html -e "http://quote.地址" %1

Vbscript设置跳过盗链检查。
一个注意事项:在HTML中,设置不起作用,这可能是防止钓鱼网站的原因。
代码如下:
Set httpObj = CreateObject("Microsoft.XmlHttp")
httpObj.open "GET", url, FALSE
'跳过盗链检查
httpObj.setRequestHeader "REFERER", "http://quote.eastmoney.com"
httpObj.send ""

星期五, 八月 24, 2007

关于Javascript的this关键词的解释.

往往在函数中使用this关键词
function checkme()
{
alert(this.value);
}

此时this代表 是当前聚焦的可视HTML元素(focus element).比如一个下拉框,输入框等等。

最严密的说法如下:

http://www.quirksmode.org/js/this.html

In JavaScript this always refers to the “owner” of the function we're executing, or rather, to the object that a function is a method of. When we define our faithful function doSomething() in a page, its owner is the page, or rather, the window object (or global object) of JavaScript. An onclick property, though, is owned by the HTML element it belongs to.

星期四, 八月 09, 2007

如何编写自己的dojo widget(物件)?

网络上有很多的方法。

包括什么使用以下方法来申明:

dojo.setModulePrefix('wang', '../wang');
dojo.registerModulePath('wang', '../wang');
dojo.widget.manager.registerWidgetPackage('wang.widget');
但会出现很多的问题和错误。

这篇文章的方法是最简单的
http://www.alexatnet.com/node/14

简单来说步骤如下:

1.建立一个目录

假设目前js目录结构如下:
/js/dojo-0.4.3-ajax
/js /wang //你自己定做的dojo widget 库
/js/wang/widget/ Memo.html, Memo.css

那么你需要建立的声明文件Menu.js保存在/js目录下.

2.建立新的widget声明文件Menu.js

Menu.js内容如下:

dojo.widget.defineWidget(
// widget name and class
"wang.widget.Memo",

// superclass
dojo.widget.HtmlWidget,

// properties and methods
{
// parameters
title: "Note",

// settings
isContainer: true,
templatePath: dojo.uri.dojoUri("../wang/widget/Memo.html"),
//注意:这个目录是相对于dojo.js所在目录的相对目录.
templateCssPath: dojo.uri.dojoUri("../wang/widget/Memo.css"),

// callbacks
onClick: function(evt){
this.destroy();
}
}
);

3.在HTML里应用声明

<script src="js/Memo.js"></script>

4.通过dojoType来使用新的widget
<div dojoType="Memo" title="你好世界">
你好吗?
</div>

效果如下:

星期三, 八月 08, 2007

Javascript的匿名函数和JSON。

http://www.json.org/
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。

JSON建构于两种结构:

  • “名称/值”对的集合(A collection of name/value pairs)。不同的语言中,它被理解为对象(object),纪录(record),结构(struct),字典(dictionary),哈希表(hash table),有键列表(keyed list),或者关联数组 (associative array)。
  • 值的有序列表(An ordered list of values)。在大部分语言中,它被理解为数组(array)。
JSON的表达语法:
object //用两个大花括号把对象数组包含起来。
{}
{ members }

members //成员
pair
pair , members
pair //标准的名字:值
string : value
array //数组用两个中括号包含起来的
[]
[ elements ]
elements
value
value , elements
value
string
number
object
array
true
false
null

简单的一个小技巧,如何把一个符合JSON数组表达的字符串转为Javascript数组对象
<script>
var arr
var str="[['line 1','line 2'],['line 1','line 2']]";
eval("arr="+str);
alert(arr[0][0]);
</script>

星期二, 七月 31, 2007

如何避免JSP文件产生空格或空白行(whitespace)

jsp的解析器,忠实的输出jsp文件里包含的没一个字符,如果发现一个<%%> 对,就会在解析完成后,则把<%%>解释后的结果输出。
所以,避免JSP文件产生空白行的办法,就是需要把所有的<%%>连起来书写,在jsp文件中减少手动的回车换行,就可以避免JSP文件产生空白行了。

比如.
<%@ page contentType="text/xml;" %><%@page import="com..dao.Mrp_Workload_Capacity_Calculate_DAO"%><%@ page import="com.sun.rowset.CachedRowSetImpl"%><%@ page import="com.util.DBUtil"%><%...%>

星期五, 七月 27, 2007

DHMTL Grid Paginal 语法.

http://www.nauticalworld.co.uk/jscripts/dhtmlxTreeGrid/samples/pro_paging_wt.html

<div id="gridbox" width="100%" height="250px" style="background-color:white;overflow:hidden"></div>//显示grid数据地方
<div id="recinfoArea" style="width:100%;"></div>//用来显示导航条的地方
<script>
mygrid = new dhtmlXGridObject('gridbox');
...
//should be called before init()
mygrid.enablePagingWT(true,10,3,"recinfoArea");
...
mygrid.init();
mygrid.setXMLAutoLoading("dynscroll.php");//如果想每次点击下一页的时候从服务器读取数据,必须要加入这一行,通过url参数rowsLoaded=N 在服务器段来获取下一页的数据

mygrid.loadXML("dynscroll.xml");//this sample uses static loading
</script>

星期三, 七月 25, 2007

Javascript匿名function(或无名unnamed)的申明

Anonymous function(or Unnamed function)语法:

var greet=function(){....}//可以有参数,或无参数。

调用的方法:greet();如果有参数,需要再调用的时候加入参数.

对象常量 Object Literals:

var car = {myCar:(function(){return "WIlliam";}), getCar: "Honda", special: "Sales"}
调用:
document.write(car.myCar()); // WIlliam
document.write(car.getCar); // Honda
document.write(car.special); // Sales
对象常量同匿名function 组合,可以写出非常复杂的表达。

var car = {myCar:(function(){return "WIlliam";}), getCar: "Honda", special: "Sales"}
document.write(car.myCar); // WIlliam
document.write(car.getCar); // Honda
document.write(car.special); // Toyota
或另一个常用语法

var Person=function(){}
Person.prototype.name="William"
Person.prototype.age=17
who=new Person();

document.write(who.name);

Javascript的匿名function 的语法主要设计到Javascript如何对面向对象的支持。

var Person=function(){}
Person.prototype = {
initialize: function(name) {
this.name = name;
},
greet: (function() {
return("Hello from " + this.name+"");
})
};

who=new Person();
who.initialize("William");
alert(who.greet());

一个比较好的地址:http://blogs.sun.com/sundararajan/entry/java_javascript_and_jython

星期五, 七月 20, 2007

dojo TabContainer Javascript控制

<div id="mainTabContainer" selectedTab="这里是{CalendarPart,vocationPart,WorkCenterPart}之一" dojoType="TabContainer" style="width: 100%; height: 26em;">
<div id="CalendarPart" dojoType="ContentPane" href="1.jsp" refreshOnShow="true" executeScripts="true" contentCache="false" label="<b>Calendar</b>"></div>
<div id="vocationPart" dojoType="ContentPane" href="2.jsp" refreshOnShow="true" executeScripts="true" contentCache="false" label="<b>Holiday</b>"></div>
<div id="WorkCenterPart" dojoType="ContentPane" href="3.jsp" refreshOnShow="true" executeScripts="true" contentCache="false" label="<b>Work Center</b>"></div>
</div>

每个contentPane内容的改变,典型使用以下Script
<script>
var obj =dojo.widget.byId("WorkCenterPart");
//alert(obj);
obj.setUrl("");//新的动态内容url
</script>

星期二, 七月 17, 2007

WINDOWS XP Dr Watson Log file.

任务管理器,选择进程,鼠标右键选择调试,然后查看log文件

c:\Documents and Settings\All Users\Application Data\Microsoft\Dr Watson\drwtsn32.log

星期日, 七月 15, 2007

飞狐 运行VBS公式出现错误处理。

在飞狐公式中运行VBS公式出现以下错误的提示:

"脚本引擎请求位置对象信息:"Wscript"",脚本引擎请求位置对象信息:"JSProxy"

解决方法:

进入windows目录下,再进入system32目录下,运行:
regsvr32 jscript.dll
regsvr32 vbscript.dll

再启动飞狐软件或股道软件就可以了。

Java Rest框架。

https://cetia4.dev.java.net/

支持:Servlet API.

支持ROR的Java框架.

http://grails.codehaus.org/

星期五, 七月 13, 2007

XML CDATA,强大的万能标签。

CDATA

Everything inside a CDATA section is ignored by the parser.

If your text contains a lot of "<" or "&" characters - as program code often does - the XML element can be defined as a CDATA section.

A CDATA section starts with "<![CDATA[" and ends with "]]>":


<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1
}
else
{
return 0
}
}
]]>
</script>

In the example above, everything inside the CDATA section is ignored by the parser.

Notes on CDATA sections:

A CDATA section cannot contain the string "]]>", therefore, nested CDATA sections are not allowed.

Also make sure there are no spaces or line breaks inside the "]]>" string.

星期四, 七月 05, 2007

动态创建复杂form之二

方法一:

formname.document.createElement("form");
document.body.appendChild(formname); //关键语句,否则submit()方法没有实际动作

//add other node
txtObj = document.createElement("input");
//1
txtObj.setAttribute("type","hidden");
txtObj.setAttribute("name","username");
txtObj.setAttribute("value","William");
formname.appendChild(txtObj);
//2
txtObj2 = document.createElement("input");
txtObj2.setAttribute("type","hidden");
txtObj2.setAttribute("name","actionTarget");
txtObj2.setAttribute("value","VacationSetting");
formname.appendChild(txtObj2);
formname.action = target;
formname.method="post";
formname.submit();

方法二:

var f = document.createElement(’form’);
document.body.appendChild(f); //关键语句,否则submit()方法没有实际动作

f.style.display = ‘none’; this.parentNode.appendChild(f);
var h = document.createElement(’input’);
h.type = ‘hidden’; h.name = ‘act’; h.value = ‘admin’;
f.appendChild(h);

var h2 = document.createElement(’input’);
h2.type = ‘hidden’; h2.name = ’setadmin’; h2.value = ‘delcat’;
f.appendChild(h2);

f.method = ‘POST’;
f.action = ‘index.php’;
f.submit();
return false

方法三:

function doIt()
{
formname = document.createElement("form");
document.body.appendChild(formname);
//add other node
txtObj = document.createElement("");
formname.appendChild(txtObj);
//2
txtObj2 = document.createElement("");
formname.appendChild(txtObj2);
//3
txtObj3 = document.createElement("");
formname.appendChild(txtObj3);

formname.action = target;
formname.method="POST";

formname.submit();
}