温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

雪山飞鹄

温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

BlogJava 首页 新随笔 联系 聚合 管理
  215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks

#

amfphp下载:http://sourceforge.net/projects/amfphp/files/amfphp/
这里我们下载amfphp 1.9.zip
下载后解压到web服务器的工作目录下,前提是您已配置好php的工作环境。这里为了简单起见,使用IIS7.0+php5.2
即:将amfphp1.9解压到C:\inetpub\wwwroot
browser:目录为amfphp可供我们直接在浏览器浏览的目录
services:目录是我们自己开发的php类文件存放目录
gateway.php是一个比较重要的文件。
打开gateway.php,定位到127行
//$gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1");
$gateway->setCharsetHandler("utf8_decode", "utf-8", "utf-8");
设置中文字符支持
如果服务器和php环境正常的话,在地址栏输入http://localhost/amfphp/browser/将会看到如下图所示
配置参数如上图所示,点save保存设置。
编写一个php与mysql交互的类。
product.php
<?php
class product{

    
function print_xml(){
    
//获取数据库连接
        $link=@mysql_connect("localhost","root","") or die('数据库连接错误');
        
//选择数据库
        mysql_select_db("compass",$link);
        
//设置数据库编码
        mysql_query("set names utf8",$link);
        
//查询数据库
        $result=mysql_query("select * from product");
        
        
//创建DOMDocument对象
        $doc = new DOMDocument('1.0','utf-8');
        
//格式化输出
        $doc->formatOutput = true;
        
        
//创建根元素
        $root = $doc->createElement('root');
        
//添加根元素
        $root = $doc->appendChild($root);
    
        
//从数据库中获取数据每一条是一个product
        while($data=mysql_fetch_assoc($result)){
            
            
//创建product标签
            $product=$doc->createElement('product');
            
//添加product标签
            $product = $root->appendChild($product);

            
//创建Id元素
            $id = $doc->createElement('id');
            
//添加Id
            $id = $product->appendChild($id);
            
//创建文本内容
            $idtext = $doc->createTextNode($data['id'].'');
            
//将文本添加到id标签内
            $idtext = $id->appendChild($idtext);
       
            
//创建name标签
            $name = $doc->createElement('name');
            
//添加name
            $name = $product->appendChild($name);
            
//创建name标签的文本
            $nametext = $doc->createTextNode($data['name'].'');
            
//设置name标签的文本
            $nametext = $name->appendChild($nametext);

            
//创建price标签
            $price = $doc->createElement('price');
            
//添加price
            $price = $product->appendChild($price);
            
//创建price标签的文本
            $pricetext = $doc->createTextNode($data['price'].'');
            
//设置price标签的文本
            $pricetext = $price->appendChild($pricetext);
        }
        
//关闭数据库连接
        mysql_close($link);
        
//保存xml
        return $doc->saveXML();
    }
}
?>

注意该文件的编写规则及存放路径
php中类文件的编写符合java中类的编写,即文件名与类名大小写一致
该文件必须存放于C:\inetpub\wwwroot\amfphp\services\目录下
方法最后使用return 返回而不是输出
http://localhost/amfphp/browser/中的浏览情况
posted @ 2011-10-28 11:18 雪山飞鹄 阅读(2801) | 评论 (0)编辑 收藏

面向HTML和PHP开发人员的Flex快速入门指南
posted @ 2011-10-27 10:36 雪山飞鹄 阅读(251) | 评论 (0)编辑 收藏

function print_xml(){
    
//获取数据库连接
        $link=@mysql_connect("localhost","root","") or die('数据库连接错误');
        
//选择数据库
        mysql_select_db("compass",$link);
        
//设置数据库编码
        mysql_query("set names utf8",$link);
        
//查询数据库
        $result=mysql_query("select * from product");
        
        
//创建DOMDocument对象
        $doc = new DOMDocument('1.0','utf-8');
        
//格式化输出
        $doc->formatOutput = true;
        
        
//创建跟元素
        $root = $doc->createElement('root');
        
//添加跟元素
        $root = $doc->appendChild($root);
    
    
//从数据库中获取数据每一条是一个product
        while($data=mysql_fetch_assoc($result)){
      
//创建Id元素
            $id = $doc->createElement('id');
            
//添加Id
            $id = $root->appendChild($id);
            
//创建文本内容
            $idtext = $doc->createTextNode($data['id'].'');
            
//将文本添加到id标签内
            $idtext = $id->appendChild($idtext);
       
      
//创建name标签
            $name = $doc->createElement('name');
            
//添加name
            $name = $root->appendChild($name);
            
//创建name标签的文本
            $nametext = $doc->createTextNode($data['name'].'');
            
//设置name标签的文本
            $nametext = $name->appendChild($nametext);

      
//创建price标签
            $price = $doc->createElement('price');
            
//添加price
            $price = $root->appendChild($price);
            
//创建price标签的文本
            $pricetext = $doc->createTextNode($data['price'].'');
            
//设置price标签的文本
            $pricetext = $price->appendChild($pricetext);
        }
        
//关闭数据库连接
        mysql_close($link);
        
//保存xml
        echo $doc->saveXML();
    }
posted @ 2011-10-27 10:33 雪山飞鹄 阅读(676) | 评论 (0)编辑 收藏

http://www.cnblogs.com/hll2008/
http://svn.apache.org/repos/asf/
http://blog.csdn.net/chenzheng_java
http://bigcat.easymorse.com/
http://blog.csdn.net/dadoneo
http://blog.csdn.net/Android_Tutor
http://www.blogjava.net/changcheng/
http://blog.csdn.net/hellogv/
http://byandby.javaeye.com/
http://blog.csdn.net/xys289187120
http://www.androidla.net/
http://www.itivy.com/android
posted @ 2011-09-14 09:14 雪山飞鹄 阅读(2785) | 评论 (0)编辑 收藏

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" minWidth="955" minHeight="600"
               creationComplete
="init()"
               
>
    
<mx:Script>
            import flash.net.navigateToURL;
            
            import mx.controls.Alert;
            
            internal var blogItem:ContextMenuItem;
            internal var authorItem:ContextMenuItem;
            internal var qqItem:ContextMenuItem;
            internal var mailItem:ContextMenuItem
            
        
            /**
             * 定制自己的右键菜单
             */
            internal function init():void{
                //创建一个右键上下文菜单
                var contextMenu:ContextMenu=new ContextMenu();
                //隐藏指定的 ContextMenu对象中的所有内置菜单项(“设置”除外)。
                contextMenu.hideBuiltInItems();
                //创建上下文菜单选项
                authorItem=new ContextMenuItem("作者:雪山飞鹄");
                //创建上下文菜单选项
                qqItem=new ContextMenuItem("QQ:184675420");
                //创建上下文菜单选项
                mailItem=new ContextMenuItem("Email:sxyx2008@163.com");
                //创建上下文菜单选项
                blogItem=new ContextMenuItem("Blog:http://www.blogjava.net/sxyx2008/");
                
                //将子菜单系添加到子菜单中
                contextMenu.customItems.push(authorItem);
                contextMenu.customItems.push(qqItem);
                contextMenu.customItems.push(mailItem);
                contextMenu.customItems.push(blogItem);
                
                //为每个子菜单项添加监听事件
                blogItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
                authorItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
                qqItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
                mailItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
                
                //为上下文菜单设置监听
                contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT,menuHandler);
                
                //将该上下文菜单赋值给当前应用环境
                this.contextMenu=contextMenu;
            }
            
            //菜单监听处理函数
            internal function menuHandler(evt:ContextMenuEvent):void{
                trace("menu");
            }    
        
        
        
            //子菜单项监听处理函数
            internal function menuItemHandler(evt:ContextMenuEvent):void{
                //获取事件源,斌将其转化为ContextMenuItem
                var item:ContextMenuItem=ContextMenuItem(evt.currentTarget);
                var caption:String=item.caption;
                switch(caption)
                {
                    case blogItem.caption:
                    {
                        //若为blog地址,则请求到该地址
                        navigateToURL(new URLRequest("http://www.blogjava.net/sxyx2008/"),"_blank");
                        break;
                    }
                    default:
                    {
                        Alert.show(caption,"右键菜单项");
                        break;
                    }
                }
            }
            
            
    
</mx:Script>
    
    
</mx:Application>
演示
http://blogagic.com/178/customizing-right-click-menu-of-flex-applications
posted @ 2011-09-09 14:00 雪山飞鹄 阅读(1578) | 评论 (0)编辑 收藏

posted @ 2011-08-26 16:43 雪山飞鹄 阅读(600) | 评论 (0)编辑 收藏

package com.xmlpull;

import java.io.File;
import java.io.FileOutputStream;

import org.kxml2.io.KXmlSerializer;
import org.xmlpull.v1.XmlSerializer;

/**
 * <pre>
 * xmlpull方式创建xml
 * </pre>
 * 
@author scott
 *
 
*/
public class XmlPullCreateXML {
    
    
public static void main(String[] args) throws Exception{
        XmlSerializer xmlSerializer
=new KXmlSerializer();
        xmlSerializer.setOutput(
new FileOutputStream(new File("D:\\workspace\\demo\\src\\students.xml")), "utf-8");
        xmlSerializer.startDocument(
nulltrue);
        xmlSerializer.startTag(
null"data");
        
for (int i = 0; i < 10; i++) {
            xmlSerializer.startTag(
null"student");
            xmlSerializer.attribute(
null"id"""+(i+1));
            
            xmlSerializer.startTag(
null"name");
            xmlSerializer.text(
"student"+i);
            xmlSerializer.endTag(
null"name");
            
            xmlSerializer.startTag(
null"age");
            xmlSerializer.text((i
+10)+"");
            xmlSerializer.endTag(
null"age");
            
            
            xmlSerializer.startTag(
null"sex");
            
if(i%2==0){
                xmlSerializer.text(
"");
            }
else{
                xmlSerializer.text(
"");
            }
            xmlSerializer.endTag(
null"sex");
            
            
            xmlSerializer.startTag(
null"address");
            xmlSerializer.text(
"陕西西安");
            xmlSerializer.endTag(
null"address");
            
            xmlSerializer.endTag(
null"student");
        }
        
        xmlSerializer.endTag(
null"data");
        
        xmlSerializer.endDocument();
        
        xmlSerializer.flush();
        
    }

}
生成的xml文件
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<data>
    
<student id="1">
        
<name>student0</name>
        
<age>10</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="2">
        
<name>student1</name>
        
<age>11</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="3">
        
<name>student2</name>
        
<age>12</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="4">
        
<name>student3</name>
        
<age>13</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="5">
        
<name>student4</name>
        
<age>14</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="6">
        
<name>student5</name>
        
<age>15</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="7">
        
<name>student6</name>
        
<age>16</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="8">
        
<name>student7</name>
        
<age>17</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="9">
        
<name>student8</name>
        
<age>18</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="10">
        
<name>student9</name>
        
<age>19</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
</data>

posted @ 2011-08-24 11:38 雪山飞鹄 阅读(1296) | 评论 (1)编辑 收藏

xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<data>
    
<student id="1">
        
<name>student0</name>
        
<age>10</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="2">
        
<name>student1</name>
        
<age>11</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="3">
        
<name>student2</name>
        
<age>12</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="4">
        
<name>student3</name>
        
<age>13</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="5">
        
<name>student4</name>
        
<age>14</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="6">
        
<name>student5</name>
        
<age>15</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="7">
        
<name>student6</name>
        
<age>16</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="8">
        
<name>student7</name>
        
<age>17</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="9">
        
<name>student8</name>
        
<age>18</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
    
<student id="10">
        
<name>student9</name>
        
<age>19</age>
        
<sex></sex>
        
<address>陕西西安</address>
    
</student>
</data>
handler
package com.sax;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.xmlpull.Student;

public class StudentHandler extends DefaultHandler {
    
    
private Student student=null;
    
private String tag;
    
private List<Student> list=null;
    
    
    
public List<Student> getList() {
        
return list;
    }

    
public void setList(List<Student> list) {
        
this.list = list;
    }
    
    
    
    @Override
    
public void characters(char[] ch, int start, int length)
            
throws SAXException {
        String data
=new String(ch,start,length);
        
if(null!=tag){
            
if("name".equalsIgnoreCase(tag)){
                student.setName(data);
            }
else if("age".equalsIgnoreCase(tag)){
                student.setAge(data);
            }
else if("sex".equalsIgnoreCase(tag)){
                student.setSex(data);
            }
else if("address".equalsIgnoreCase(tag)){
                student.setAddress(data);
            }
        }
    }

    @Override
    
public void endDocument() throws SAXException {
        
    }

    @Override
    
public void endElement(String uri, String localName, String name)
            
throws SAXException {
        
if("student".equalsIgnoreCase(name)){
            list.add(student);
            student
=null;
        }
        tag
=null;
    }

    @Override
    
public void startDocument() throws SAXException {
        list
=new ArrayList<Student>();
    }

    @Override
    
public void startElement(String uri, String localName, String name,
            Attributes attributes) 
throws SAXException {
        
if("student".equals(name)){
            student
=new Student();
            
if(attributes!=null){
                student.setId(Integer.parseInt(attributes.getValue(
0)));
            }
        }
        tag
=name;
    }
    
    
    
}
SaxXmlParse
package com.sax;

import java.io.File;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import com.xmlpull.Student;

/**
 * <pre>
 * sax解析xml
 * </pre>
 * 
@author scott
 *
 
*/
public class SaxXmlParse{
    
    
public List<Student> parseXML() throws Exception{
        SAXParserFactory parserFactory
=SAXParserFactory.newInstance();
        SAXParser parser 
= parserFactory.newSAXParser();
        
//XMLReader reader=parser.getXMLReader();
        StudentHandler studentHandler=new StudentHandler();
        
//reader.setContentHandler(studentHandler);
        
//reader.parse(new InputSource(new FileInputStream(new File("D:\\workspace\\demo\\src\\students.xml"))));
        parser.parse(new File("D:\\workspace\\demo\\src\\students.xml"), studentHandler);
        
return studentHandler.getList();
    }
    
    
    
public static void main(String[] args) throws Exception{
        List
<Student> list=new SaxXmlParse().parseXML();
        
for (Student stu : list) {
            System.out.println(stu.getId()
+"\t"+stu.getName()+"\t"+stu.getSex()+"\t"+stu.getAge()+"\t"+stu.getAddress());
        }
    }
    
    
    
    
    
}
效果图
1 student0 女 10 陕西西安
2 student1 男 11 陕西西安
3 student2 女 12 陕西西安
4 student3 男 13 陕西西安
5 student4 女 14 陕西西安
6 student5 男 15 陕西西安
7 student6 女 16 陕西西安
8 student7 男 17 陕西西安
9 student8 女 18 陕西西安
10 student9 男 19 陕西西安



posted @ 2011-08-24 11:36 雪山飞鹄 阅读(1405) | 评论 (0)编辑 收藏

xml文件
<?xml version="1.0" encoding="UTF-8"?>
<data>
    
<book id="1">
        
<name>Android应用开发详解</name>
        
<author>json</author>
        
<price>88</price>
        
<pubinfo>人民邮电出版社</pubinfo>
    
</book>
    
<book id="2">
        
<name>Android权威指南</name>
        
<author>tom</author>
        
<price>79</price>
        
<pubinfo>人民教育出版社</pubinfo>
    
</book>
    
<book id="3">
        
<name>Android开发案例大全</name>
        
<author>mark</author>
        
<price>68</price>
        
<pubinfo>电子工业出版社</pubinfo>
    
</book>
    
<book id="4">
        
<name>Android从入门到精通</name>
        
<author>jack</author>
        
<price>68</price>
        
<pubinfo>电子工业出版社</pubinfo>
    
</book>
    
<book id="5">
        
<name>Pro Spring</name>
        
<author>mark</author>
        
<price>68</price>
        
<pubinfo>电子工业出版社</pubinfo>
    
</book>
</data>
解析类
package com.dom;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
 * <pre>
 * dom解析xml
 * <pre>
 * 
@author scott
 *
 
*/
public class DomXmlParser {

    
public static void main(String[] args) {
        DocumentBuilderFactory factory
=DocumentBuilderFactory.newInstance();
        File file
=new File("D:\\workspace\\demo\\src\\books.xml");
        DocumentBuilder documentBuilder
=null;
        
try {
            documentBuilder 
= factory.newDocumentBuilder();
        } 
catch (ParserConfigurationException e) {
            e.printStackTrace();
        }
        Document document
=null;
        
try {
            document
=documentBuilder.parse(file);
        } 
catch (SAXException e) {
            e.printStackTrace();
        } 
catch (IOException e) {
            e.printStackTrace();
        }
        
        Element element
=document.getDocumentElement();
        NodeList nodeList
=element.getElementsByTagName("book");
        
for (int i = 0; i < nodeList.getLength(); i++) {
            Element book 
= (Element)nodeList.item(i);
            String id
=book.getAttribute("id");
            
            Element bookname
=(Element) book.getElementsByTagName("name").item(0);
            String name
=bookname.getFirstChild().getNodeValue();
            
            Element bookauthor
=(Element) book.getElementsByTagName("author").item(0);
            String author
=bookauthor.getFirstChild().getNodeValue();
            
            Element bookprice
=(Element) book.getElementsByTagName("price").item(0);
            String price
=bookprice.getFirstChild().getNodeValue();
            
            Element bookpubinfo
=(Element) book.getElementsByTagName("pubinfo").item(0);
            String pubinfo
=bookpubinfo.getFirstChild().getNodeValue();
            
            System.out.println(id
+","+name+","+author+","+price+","+pubinfo);
            
        }
        
        
        
    }

}
效果
1,Android应用开发详解,json,88,人民邮电出版社
2,Android权威指南,tom,79,人民教育出版社
3,Android开发案例大全,mark,68,电子工业出版社
4,Android从入门到精通,jack,68,电子工业出版社
5,Pro Spring,mark,68,电子工业出版社

posted @ 2011-08-24 11:32 雪山飞鹄 阅读(415) | 评论 (0)编辑 收藏

     摘要: Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->package com.dom;import java.io.File;import java.util.List;import javax.xml.parsers...  阅读全文
posted @ 2011-08-24 11:29 雪山飞鹄 阅读(456) | 评论 (0)编辑 收藏

仅列出标题
共22页: 上一页 1 2 3 4 5 6 7 8 9 下一页 Last