bcoder

12月 252012
 

Pull也是一个轻量级的解析xml的类,类似sax,边取边读,占用内存小,避免让app产生oom的问题。

解析使用的类为XmlPullParser,XmlPullParser分节点读取,每到节点的开始或者结尾时会触发相应的事件(event),开发人员可以在这些事件中处理数据,常用到的事件有:START_DOCUMENT、END_DOCUMENT、START_TAG、END_TAG。

Pull方式和sax的区别如下:
1. Pull的解析放在一个函数中就可以了,而sax必须新建一个Handler类来处理xml.
2. 正因为sax需要一个Handler来处理事件,它本身无法控制何时停止解析,而Pull在不需要后面数据的时候可以停止事件处理,退出解析

下面是一个测试xml文件:

下面是使用XmlPullParser解析xml的代码:

 

 

 Posted by on 2012-12-25

XML的NodeName的特殊值

 分类:Other 阅读 (2,381)  1 Response »
12月 242012
 

今天写一个用Java读取XML文件的代码的时候,突然在for循环里发现NodeName=#text的情况,翻来覆去的看XML并没有发现有NodeName为#text的节点。GG了一下才发现原来XML的NodeName并不只是按“<”右边的节点名来定义的,在W3C的文档中还定义了一些特殊的NodeName。

下面先看一下W3C文档中对NodeName的定义

Interface nodeName
Element The tag name, eg. HTML
Attr The attribute name, eg. id
Text #text
CDATASection #cdata-section
EntityReference The name of the entity reference, eg. amp
Entity The entity name, eg. &
ProcessingInstruction The target of the processing instruction, eg.xml-stylesheet
Comment #comment
Document #document
DocumentType The name of the document type, eg. html
DocumentFragment #document-fragment
Notation The notation name

本人今天使用的XML如下:

在两个<User..>的前面各有一个#text类型的Node,乍一看什么都没有啊?其实<UserList>和下行的<User…>之间是有一堆的空格的,于是这堆空格就被当成了#text类型。将XML改成如下样子后就没有那两个#text类型的Node了

现在也明白为什么有的地方会用如下的判断节点类型的代码了

 

 

 

 Posted by on 2012-12-24

Eclipse快捷键大全

 分类:Other 阅读 (2,021)  No Responses »
12月 192012
 

调试

F11 开始调试
Ctrl+F11 开始执行程序
Ctrl+Shift+B  创建/取消断点
F5  步进调试,如遇子函数进入子函数中调试
F6  步进调试,不进入子函数调试
F7  跳出本函数并定位到调用本函数的地方
F8  运行程序
Ctrl+F2  结束调试

编辑器

Ctrl+Shift+O 管理Import部分,将代码中需要引入但还没引入的单元添加到import头
Ctrl+D 删除本行代码
Ctrl+M 最大化面板窗口
F3 跳转代码到光标所在类的定义处
Alt+左方向键 回到上一次按F3的地方
Ctrl+Shift+1 添加书签(本人自定义)
Alt+Shift+S 打开Source菜单

12月 102012
 

因为在Delphi 2009及更高的版本中,已增加对Unicode的支持,所以当在此版本中调用Windows Api的时候调用的都是Unicode版本的Api,比如:调用CreateProcess时实际是调用的CreateProcessW,在之前的版本则是调用的是CreateProcessA。

同样地,如果声明的是string类型,则此变量也是Unicode类型的字符串变量,使用此种类型的变量作为参数是没有问题,但是如果把变量强制声明成了AnsiString再作为参数传入的话则会出现问题了。

以CreateFile函数为例,第一个参数为lpFileName,为要打开的文件路径,如果传入的是String类型的变量,则可以执行成功,如果传入的是AnsiString类型的变量则会失败,用GetLastError会得到文件未找到的错误ERROR_FILE_NOT_FOUND (2)。

NSIS中的系统路径常量

 分类:NSIS 阅读 (13,431)  No Responses »
12月 032012
 

$PROGRAMFILES, $PROGRAMFILES32, $PROGRAMFILES64

The program files directory (usually C:Program Files but detected at runtime). On Windows x64, $PROGRAMFILES and $PROGRAMFILES32 point to C:Program Files (x86) while $PROGRAMFILES64 points to C:Program Files. Use $PROGRAMFILES64 when installing x64 applications.

$COMMONFILES, $COMMONFILES32, $COMMONFILES64

The common files directory. This is a directory for components that are shared across applications (usually C:Program FilesCommon Files but detected at runtime). On Windows x64, $COMMONFILES and $COMMONFILES32 point to C:Program Files (x86)Common Files while $COMMONFILES64 points to C:Program FilesCommon Files. Use $COMMONFILES64 when installing x64 applications.

$DESKTOP

The Windows desktop directory (usually C:WindowsDesktop but detected at runtime). The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$EXEDIR

The directory containing the installer executable (technically you can modify this variable, but it is probably not a good idea).

$EXEFILE

The base name of the installer executable.

$EXEPATH

The full path of the installer executable.

${NSISDIR}

A symbol that contains the path where NSIS is installed. Useful if you want to call resources that are in NSIS directory e.g. Icons, UIs etc.

When compiled with support for keeping makensis and the data in the same place (the default on Windows), it is in the same place as makensis, on other platforms it is set at compile time (See the INSTALL file for info). In both instances you can modify it at runtime by setting the NSISDIR environment variable. See section 3.1.3 for more info.

$WINDIR

The Windows directory (usually C:Windows or C:WinNT but detected at runtime).

$SYSDIR

The Windows system directory (usually C:WindowsSystem or C:WinNTSystem32 but detected at runtime).

$TEMP

The system temporary directory (usually C:WindowsTemp but detected at runtime).

$STARTMENU

The start menu folder (useful in adding start menu items using CreateShortCut). The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$SMPROGRAMS

The start menu programs folder (use this whenever you want $STARTMENUPrograms). The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$SMSTARTUP

The start menu programs / startup folder. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$QUICKLAUNCH

The quick launch folder for IE4 active desktop and above. If quick launch is not available, simply returns the same as $TEMP.

$DOCUMENTS

The documents directory. A typical path for the current user is C:Documents and SettingsFooMy Documents. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

This constant is not available on Windows 95 with Internet Explorer 4 not installed.

$SENDTO

The directory that contains Send To menu shortcut items.

$RECENT

The directory that contains shortcuts to the user’s recently used documents.

$FAVORITES

The directory that contains shortcuts to the user’s favorite websites, documents, etc. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

This constant is not available on Windows 95 with Internet Explorer 4 not installed.

$MUSIC

The user’s music files directory. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

This constant is available on Windows XP, ME and above.

$PICTURES

The user’s picture files directory. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

This constant is available on Windows 2000, XP, ME and above.

$VIDEOS

The user’s video files directory. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

This constant is available on Windows XP, ME and above.

$NETHOOD

The directory that contains link objects that may exist in the My Network Places/Network Neighborhood folder.

This constant is not available on Windows 95 with Internet Explorer 4 and Active Desktop not installed.

$FONTS

The system’s fonts directory.

$TEMPLATES

The document templates directory. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

$APPDATA

The application data directory. Detection of the current user path requires Internet Explorer 4 and above. Detection of the all users path requires Internet Explorer 5 and above. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

This constant is not available on Windows 95 with Internet Explorer 4 and Active Desktop not installed.

$LOCALAPPDATA

The local (nonroaming) application data directory.

This constant is available on Windows 2000 and above.

$PRINTHOOD

The directory that contains link objects that may exist in the Printers folder.

This constant is not available on Windows 95 and Windows 98.

$INTERNET_CACHE

Internet Explorer’s temporary internet files directory.

This constant is not available on Windows 95 and Windows NT with Internet Explorer 4 and Active Desktop not installed.

$COOKIES

Internet Explorer’s cookies directory.

This constant is not available on Windows 95 and Windows NT with Internet Explorer 4 and Active Desktop not installed.

$HISTORY

Internet Explorer’s history directory.

This constant is not available on Windows 95 and Windows NT with Internet Explorer 4 and Active Desktop not installed.

$PROFILE

The user’s profile directory. A typical path is C:Documents and SettingsFoo.

This constant is available on Windows 2000 and above.

$ADMINTOOLS

A directory where administrative tools are kept. The context of this constant (All Users or Current user) depends on the SetShellVarContext setting. The default is the current user.

This constant is available on Windows 2000, ME and above.

$RESOURCES

The resources directory that stores themes and other Windows resources (usually C:WindowsResources but detected at runtime).

This constant is available on Windows XP and above.

$RESOURCES_LOCALIZED

The localized resources directory that stores themes and other Windows resources (usually C:WindowsResources1033 but detected at runtime).

This constant is available on Windows XP and above.

$CDBURN_AREA

A directory where files awaiting to be burned to CD are stored.

This constant is available on Windows XP and above.

$HWNDPARENT

The decimal HWND of the parent window.

$PLUGINSDIR

The path to a temporary folder created upon the first usage of a plug-in or a call to InitPluginsDir. This folder is automatically deleted when the installer exits. This makes this folder the ideal folder to hold INI files for InstallOptions, bitmaps for the splash plug-in, or any other file that a plug-in needs to work.

Values work on Windows XP system user tester,在Windows Xp中登录用户为tester时的一些常量值

Values work on Windows7 64bit, system user ldr,在64位Windows7 中登录用户为ldr时的一些常量值

Values work on Windows 7 64bit, system user administrator,在64位Windows 7中登录用户为administrator时的一些常量值

 

I modified from a NSIS example script to show the above variables,运行此脚本可以生成一个在你系统上的常量值列表。

 注意*******************************:

1. 对于有些系统路径NSIS是没有相关的常量值的,如果你在几种操作系统上检查此路径全部一样的话,可以用此路径的绝对路径来处理。
2. For the folders with system account name, if you want to store data to the corresponding folders for ALL USERS, you an use a micro  SetShellVarContext all (in Function .onInit)
对于目录中带有当前用户的目录,如果你想把数据存到All Users的相应目录下,使用宏 SetShellVarContext all(在Function .onInit中)进行转换,SetShellVarContext current为切换到当前用户相应目录

 

11月 102012
 

出于安全考虑,windows7默认是把administrator用户禁用的,而是使用装系统时创建的用户登录的,虽然创建的用户也是属于管理员组的,但是使用的时候也可能发生软件不能安装或者软件安装后使用起来不能保存设置等问题。如果你对安全性要求不是非常严格的话,大可以设置使用administrator来登录,来减少使用软件时的问题。具体操作方法如下:

在“计算机”图标上右键,在弹出的菜单上点击“管理”按钮。

在弹出的“计算机管理”窗口中选择本地用户和组->用户,双击administrator用户,在弹出的administrator 属性窗口中,将“帐户已禁用”的勾去掉,点击确定,重启就可以选择administrator登录了。

computer manage window

设置使用administrator为默认用户

重新启动系统后就可以选择administrator登录了,如果省掉这个操作可以使用如下两种办法来解决

1. Windows Xp中点击开始->运行或者按Windows+R组合键,Windows 7中点击开始->所有程序->附件->运行或者按Windows+R组合键,在弹出的窗口中输入control userpasswords2后按确定按钮,选择默认登录的用户名,将“要使用本机,用户必须输入用户名和密码”前的对勾去掉,点击确定按钮后会弹出一个窗口让你输入新密码,如果不需要密码直接点确定关闭密码设置窗口,点击确定退出默认用户窗口。

control userpasswords2

设置windows默认登录用户

2. 禁用或者删除掉安装系统时创建的用户。在“计算机”图标点击右键->管理,选择本地用户和组->用户,双击要禁用的帐户,将“帐户已禁用”前面的对勾选中,点击确定即可。

11月 092012
 

1. 下载和安装JDK

下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html

jdk_down_list

点击链接进入下载页面

接受授权协议并点击相应的版本进行下载

install jdk

运行安装程序,并根据提示一步一步进行安装

2.下载Android SDK

打开页面http://developer.android.com/sdk/index.html下载并安装Android SDK

3. 下载Eclipse

Eclipse下载地址http://www.eclipse.org/downloads/,打开页面根据自己的需要选择相应的版本,初学者可能会对Eclipse的版本非常的迷惑,下面笔者做些简单的介绍

eclipse download list
eclipse download list
A. 安装包的种类

在下载页面,大家可以看到Eclipse IDE for Java EE Developers、Eclipse IDE for Java Developers、Eclipse IDE for C/C++ Developers等等,其实这些不同的安装包都是用的一样的Eclipse核心,不同的是各个包所包含的模块各不相同,具体的模块包含情况大家可以查看这个页面http://www.eclipse.org/downloads/compare.php。大家可以选择适合自己的包进行下载,如果需要其他的模块以后是可以在Eclipse中进行更新下载的。

默认放在第一个的是Eclipse IDE for Java EE Developers,如果不知道选择哪个包就选择这个就可以了。

B. Eclipse的版本和别名
  • Eclipse Juno(2012 – V4.2)
  • Eclipse Indigo(2011 – V3.7)
  • Eclipse Helios(2010 – V3.6)
  • Eclipse Galileo(2009 – V3.5)
  • Eclipse Ganymede(2008 – V3.4)
  • Eclipse Europa(2007 – V3.3)
eclipse download version list
eclipse download version list

具体细节大家可以看这个页面http://wiki.eclipse.org/Older_Versions_Of_Eclipse

4. 下载Eclipse插件For Android

JDK安装完毕,解压Eclipse压缩包,可以启动Eclipse啦!下面介绍如何在Eclipse中下载和安装Android插件的方法。

打开Eclipse,第一次打开的时候后提醒你设置WorkSpace路径,即项目文件默认的存放目录,设置成你自己使用的路径即可。Eclipse打开后,执行菜单Help->Install New SoftWare,这时弹出一个Install窗口,在Work WIth里输入https://dl-ssl.google.com/android/eclipse/,然后点击右边的“ADD”按钮,在弹出的窗口中输入这个更新的名字,名字随意,笔者输入的为”Android SDK”,点“确定”按钮。

此时在Install窗口中间的列表中应该显示可以下载的文件列表,如果列表没有显示出来请使用后面的内容进行处理。

如果列表没有加载进来,说明下载更新信息失败,因为dl-ssl.google.com这个域名在国内被屏蔽了,所以有的时候访问有些问题,可以尝试下面方法解决

a. 修改C:WindowsSystem32driversetchosts文件,在文件内添加一行内74.125.237.1 dl-ssl.google.com

如果下载过程中提示Warning: You are installing software that contains unsigned content. The authenticity or validity of this software cannot be established. Do you want to continue with the installation?直接点OK忽略即可。

选择要安装的项目,点击”Next”按钮,Eclipse检查系统环境,检查完毕再点击“Next”按钮,选中”I accept the terms of the license agreement.”,点击“Finish”按钮就开始下载了。

如果用http地址的方式下载不了,你也可以百度搜索“adt离线包”,点击“Add”按钮后,输入“Name”,然后点击“Archive”按钮,选择下载的离线包进行安装。

其他说明:

1. 如果安装Android SDK时提示没有找到JDK,需要设置环境变量java_home,则按如下方式操作:打开系统环境变量设置,增加系统变量JAVA_HOME值为JDK的路径,如果没有CLASSPATH项,增加CLASSPATH设置值为%JAVA_HOME%lib,如果已经有CLASSPATH则修改此项增加%JAVA_HOME%lib用分号隔开

2. 如果安装完毕后出现一些其他的问题,则下载个旧版本的Eclipse试试

Windows7个性化设置

 分类:Windows 阅读 (2,090)  No Responses »
11月 062012
 

1. 去掉Windows7中快捷方式的小箭头

设置方法: 打开注册表编辑器(按Windows键+R,输入Regedit后按回车键),按此路径搜索[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows CurrentVersionExplorerShell Icons],如果没有相应的路径则创建,在右侧窗口点击鼠标右键,新建->字符串值,名称为29,双击该新值的项,输入值%systemroot%system32imageres.dll,196,确定,现在 注销或者重启系统就可以了。
恢复方法: 删除项名为29的这个项
其他说明: 网上流传的设置值为C:WindowsEmpty,0或者删除lnkfile中IsShortCut的方法都有副作用或者不适用于Windows7
10月 312012
 

原来用Delphi处理XML文件就感觉头疼,不知道该用哪种方法比较好,现在将方法总结如下:

本文中演示用到的XML文件

1. 使用msxml

msxml实际上是Delphi导入的Windows的msxml2.dll,所以最终是使用的windows的方法去解析的xml文件。在PHP中对XML的解析也是用的MSXML,与Delphi的各函数都非常的类似。使用时需要在uses中加入mshtml。读取XML文件的代码

写XML文件的代码

用此方法生成的XML文件没有被格式化,即不是一个NODE一行,如果需要格式化输入,需要使用SaxWriter输出到文件。
另外还有一些其他比较有意思的方法,如:cloneNode,以后应该能用得到。

2. 使用TXmlDocument读写XML

读取XML文件

写XML文件

注意事项:

10月 292012
 

Cookie是网站存在用户本地的一些变量,用于保存一些数据以识别用户的身份或者记录用户偏好设置等。
使用smartsniff等网络截包工具查看,当执行请求时实际上是在http请求数据里加入了cookie: key1=value1; key2=value2 …这样的值,返回数据时是类似set-cookie: key1=value1这样的值。
因为我们完全可以在用TIdHttp执行网络请求的时候模拟自己的cookie值并发送到服务器端。
这里要先说明一些TIdhttp的一个属性,AllowCookies,当此值为False时允许用户发送自定义的cookie,当此值为True时,不允许用户发送自定义的cookie。
下面是一段代码: