Dom4j 学习笔记

dom4j 是一种解析 XML 文档的开放源代码 XML 框架。dom4j下载地址
本文主要记载了一些简单的使用方法。

一、xml文件的解析

dom4j既可以解析普通的xml文件,也可以解析一个InputStream,先看看xml文件长什么样子:

<books><book><id>1</id><name>Java编程思想</name><price>80</price><author>张三</author></book><book><id>2</id><name>三国演义</name><price>30</price><author>罗贯中</author></book><book><id>3</id><name>红楼梦</name><price>35</price><author>曹雪芹</author></book><book><id>4</id><name>西游记</name><price>25</price><author>吴承恩</author></book><book><id>5</id><name>水浒传</name><price>30</price><author>施耐庵</author></book>
</books>

通过读取这一段xml文件并解析,将xml文件中的内容存储到javabean中。

    private List<Book> bs;private Book b;//读取xml文件获得Document对象@Testpublic void test1(){try {//1.读取xml文件,获取document对象SAXReader reader = new SAXReader();Document document = reader.read(new File("F:\\test\\books.xml"));//2.获取根节点<books>Element root = document.getRootElement();bs = new ArrayList<Book>();//3.迭代,获取根节点的所有子节点<book>for (Iterator<Element> es = root.elementIterator(); es.hasNext();) {Element e = es.next();b = new Book();//4.再次迭代,获取子节点的子节点<id><name><price><author>for (Iterator<Element> e_son = e.elementIterator();e_son.hasNext();) {Element ee = e_son.next();if(ee.getName().equals("id")){b.setId(Integer.parseInt(ee.getText().toString()));}else if(ee.getName().equals("name")){b.setName(ee.getText());}else if(ee.getName().equals("price")){b.setPrice(Integer.parseInt(ee.getText()));}else if(ee.getName().equals("auhtor")){b.setAuthor(ee.getText());}}bs.add(b);}} catch (DocumentException e) {e.printStackTrace();}for (Book bk : bs) {System.out.println(bk.getName());}}

Book.java

public class Book {private int id;private String name;private int price;private String author;private Detail detail;private Attribute attribute;public Attribute getAttribute() {return attribute;}public void setAttribute(Attribute attribute) {this.attribute = attribute;}public Detail getDetail() {return detail;}public void setDetail(Detail detail) {this.detail = detail;}public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getPrice() {return price;}public void setPrice(int price) {this.price = price;}public String getAuthor() {return author;}public void setAuthor(String author) {this.author = author;}
}

Attribute.java

public class Attribute {private String category;private String edition;public String getCategory() {return category;}public void setCategory(String category) {this.category = category;}public String getEdition() {return edition;}public void setEdition(String edition) {this.edition = edition;}}

Detail.java

public class Detail {private String pressTime;private String storyTime;public String getPressTime() {return pressTime;}public void setPressTime(String pressTime) {this.pressTime = pressTime;}public String getStoryTime() {return storyTime;}public void setStoryTime(String storyTime) {this.storyTime = storyTime;}
}

这里写图片描述

好,我们稍微修改一下xml文件,再看看个该如何解析:

<books><book><id>1</id><name>Java编程思想</name><price>80</price><author>张三</author><detail><pressTime>天朝</pressTime><storyTime>21世纪</storyTime></detail></book><book><id>2</id><name>三国演义</name><price>30</price><author>罗贯中</author><detail><pressTime>明朝</pressTime><storyTime>汉末</storyTime></detail></book><book><id>3</id><name>红楼梦</name><price>35</price><author>曹雪芹</author><detail><pressTime>清朝</pressTime><storyTime>不详</storyTime></detail></book><book><id>4</id><name>西游记</name><price>25</price><author>吴承恩</author><detail><pressTime>明朝</pressTime><storyTime>大唐</storyTime></detail></book><book><id>5</id><name>水浒传</name><price>30</price><author>施耐庵</author><detail><pressTime>明朝</pressTime><storyTime>大宋</storyTime></detail></book>
</books>

又多了一层嵌套,看解析方式:

    private List<Book> bs;private Book b;private Detail detail;// 读取xml文件获得Document对象@Testpublic void test1() {try {// 1.读取xml文件,获取document对象SAXReader reader = new SAXReader();Document document = reader.read(new File("F:\\test\\books.xml"));// 2.获取根节点<books>Element root = document.getRootElement();bs = new ArrayList<Book>();// 3.迭代,获取根节点的所有子节点<book>for (Iterator<Element> es = root.elementIterator(); es.hasNext();) {Element e = es.next();b = new Book();// 4.再次迭代,获取子节点的子节点<id><name><price><author>for (Iterator<Element> e_son = e.elementIterator(); e_son.hasNext();) {Element ee = e_son.next();if (ee.getName().equals("id")) {b.setId(Integer.parseInt(ee.getText().toString()));} else if (ee.getName().equals("name")) {b.setName(ee.getText());} else if (ee.getName().equals("price")) {b.setPrice(Integer.parseInt(ee.getText()));} else if (ee.getName().equals("auhtor")) {b.setAuthor(ee.getText());} else if (ee.getName().equals("detail")) {detail = new Detail();for (Iterator<Element> ds = ee.elementIterator(); ds.hasNext();) {Element d = ds.next();if (d.getName().equals("pressTime")) {detail.setPressTime(d.getText());} else if (d.getName().equals("storyTime")) {detail.setStoryTime(d.getText());}}b.setDetail(detail);}}bs.add(b);}} catch (DocumentException e) {e.printStackTrace();}for (Book bk : bs) {System.out.println(bk.getName()+","+bk.getDetail().getPressTime());}}

继续修改xml文件,为之添加属性:

<books><book category="编程技术" edition="8"><id>1</id><name>Java编程思想</name><price>80</price><author>张三</author><detail><pressTime>天朝</pressTime><storyTime>21世纪</storyTime></detail></book><book category="历史小说" edition="1"><id>2</id><name>三国演义</name><price>30</price><author>罗贯中</author><detail><pressTime>明朝</pressTime><storyTime>汉末</storyTime></detail></book><book category="小说" edition="2"><id>3</id><name>红楼梦</name><price>35</price><author>曹雪芹</author><detail><pressTime>清朝</pressTime><storyTime>不详</storyTime></detail></book><book category="神话小说" edition="4"><id>4</id><name>西游记</name><price>25</price><author>吴承恩</author><detail><pressTime>明朝</pressTime><storyTime>大唐</storyTime></detail></book><book category="小说" edition="5"><id>5</id><name>水浒传</name><price>30</price><author>施耐庵</author><detail><pressTime>明朝</pressTime><storyTime>大宋</storyTime></detail></book>
</books>

给每一个book都添加了属性,又该怎么遍历呢?attribute的遍历和element的遍历非常类似,看代码:

    // 读取xml文件获得Document对象@Testpublic void test1() {try {// 1.读取xml文件,获取document对象SAXReader reader = new SAXReader();Document document = reader.read(new File("F:\\test\\books.xml"));// 2.获取根节点<books>Element root = document.getRootElement();bs = new ArrayList<Book>();// 3.迭代,获取根节点的所有子节点<book>for (Iterator<Element> es = root.elementIterator(); es.hasNext();) {Element e = es.next();b = new Book();book_attr = new lenve.test.Attribute();for (Iterator<Attribute> as = e.attributeIterator();as.hasNext();) {Attribute attr = as.next();if(attr.getName().equals("category")){book_attr.setCategory(attr.getText());}else if(attr.getName().equals("edition")){book_attr.setEdition(attr.getText());}}b.setAttribute(book_attr);// 4.再次迭代,获取子节点的子节点<id><name><price><author>for (Iterator<Element> e_son = e.elementIterator(); e_son.hasNext();) {Element ee = e_son.next();if (ee.getName().equals("id")) {b.setId(Integer.parseInt(ee.getText().toString()));} else if (ee.getName().equals("name")) {b.setName(ee.getText());} else if (ee.getName().equals("price")) {b.setPrice(Integer.parseInt(ee.getText()));} else if (ee.getName().equals("auhtor")) {b.setAuthor(ee.getText());} else if (ee.getName().equals("detail")) {detail = new Detail();for (Iterator<Element> ds = ee.elementIterator(); ds.hasNext();) {Element d = ds.next();if (d.getName().equals("pressTime")) {detail.setPressTime(d.getText());} else if (d.getName().equals("storyTime")) {detail.setStoryTime(d.getText());}}b.setDetail(detail);}}bs.add(b);}} catch (DocumentException e) {e.printStackTrace();}for (Book bk : bs) {System.out.println(bk.getName()+","+bk.getDetail().getPressTime()+","+bk.getAttribute().getCategory());}}

如果我们只想遍历某一个节点呢?比如我们只想遍历名称为id的节点,该怎么办?

    private List<Book> bs;private Book b;@Testpublic void test2() {try {// 1.读取xml文件,获取document对象SAXReader reader = new SAXReader();Document document = reader.read(new File("F:\\test\\books.xml"));// 2.获取根节点<books>Element root = document.getRootElement();bs = new ArrayList<Book>();// 3.迭代,获取根节点的所有子节点<book>for (Iterator<Element> es = root.elementIterator(); es.hasNext();) {Element e = es.next();b = new Book();// 4.再次迭代,获取子节点的子节点<id><name><price><author>for (Iterator<Element> e_son = e.elementIterator("id"); e_son.hasNext();) {Element ee = e_son.next();b.setId(Integer.parseInt(ee.getText().toString()));}bs.add(b);}} catch (DocumentException e) {e.printStackTrace();}for (Book bk : bs) {System.out.println(bk.getId()+","+bk.getAuthor());}}

输出:
这里写图片描述

最后一个问题,怎样以字符串的形式拿到一个xml文件:

    @Testpublic void test3(){try {SAXReader reader = new SAXReader();Document document = reader.read(new File("F:\\test\\books.xml"));String text = document.asXML();System.out.println(text);} catch (DocumentException e) {e.printStackTrace();}}

二、使用程序写一个xml文件

1.怎样把一个字符串文件写成xml文件:

    @Testpublic void test4() {try {String text = "<fruits><fruit><name>苹果</name><color>red</color><price>3元</price></fruit></fruits>";Document document = DocumentHelper.parseText(text);//两种方式皆可
//          FileWriter out = new FileWriter(new File("F:\\test\\str2xml.xml"));PrintWriter out = new PrintWriter(new File("F:\\test\\s2x.xml"));document.write(out);out.close();} catch (DocumentException e) {e.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}

这样输出的xml文件没有格式,可读性较差,换个方式再看看:

    @Testpublic void test5() {try {String text = "<fruits><fruit><name>苹果</name><color>red</color><price>3元</price></fruit></fruits>";Document document = DocumentHelper.parseText(text);PrintWriter out = new PrintWriter(new File("F:\\test\\s2x1.xml"));XMLWriter writer = new XMLWriter(out, new OutputFormat().createPrettyPrint());writer.write(document);writer.close();} catch (DocumentException e) {e.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}

输出结果:
这里写图片描述

这样的输出格式也是极好的。

2.通过程序一个元素一个元素的写入:

    @Testpublic void test6(){int res = createXMLFile();if(res==1){System.out.println("xml文件创建成功!");}else{System.out.println("xml文件创建失败!");}}public int createXMLFile(){//返回0表示创建成功,返回1表示创建失败int result = 0;Document document = DocumentHelper.createDocument();//建立根节点Element root = document.addElement("fruits");//加入注释root.addComment("this is a xml about fruit");Element f1 = root.addElement("fruit");f1.addAttribute("color", "red");Element f11 = f1.addElement("price");f11.setText("10元");Element f12 = f1.addElement("shape");f12.setText("圆形");Element f13 = f1.addElement("name");f13.setText("苹果");//将xml写入文件中try {PrintWriter out = new PrintWriter(new File("F:\\test\\111.xml"));XMLWriter writer = new XMLWriter(out, new OutputFormat().createPrettyPrint());writer.write(document);writer.close();result = 1;} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return result;}

这里写图片描述

再看看新创建的xml文件长什么样:

这里写图片描述

这里使用最多的就是三个方法,一个是addElement(),一个是addAttribute(),还有一个是setText(),对每一个节点都可以执行这三个操作,你想创建的任何形状的xml都可以通过层层的嵌套实现。

如果想手动指定输出编码格式:

    @Testpublic void test6(){int res = createXMLFile();if(res==1){System.out.println("xml文件创建成功!");}else{System.out.println("xml文件创建失败!");}}public int createXMLFile(){//返回0表示创建成功,返回1表示创建失败int result = 0;Document document = DocumentHelper.createDocument();//建立根节点Element root = document.addElement("fruits");//加入注释root.addComment("this is a xml about fruit");Element f1 = root.addElement("fruit");f1.addAttribute("color", "red");Element f11 = f1.addElement("price");f11.setText("10元");Element f12 = f1.addElement("shape");f12.setText("圆形");Element f13 = f1.addElement("name");f13.setText("苹果");//将xml写入文件中try {PrintWriter out = new PrintWriter(new File("F:\\test\\111.xml"));OutputFormat format = OutputFormat.createPrettyPrint();//缩进显示//默认输出编码是UTF-8,可以手动设置为GBKformat.setEncoding("GBK");XMLWriter writer = new XMLWriter(out, format);writer.write(document);writer.close();result = 1;} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return result;}

输出的xml文件为(注意看编码):

这里写图片描述

三、修改xml文件

我们要修改一下xml文件:

<books><book category="编程技术" edition="8"><id>1</id><name>Java编程思想</name><price>80</price><author>张三</author><detail><pressTime>天朝</pressTime><storyTime>21世纪</storyTime></detail></book><book category="历史小说" edition="1"><id>2</id><name>三国演义</name><price>30</price><author>罗贯中</author><detail><pressTime>明朝</pressTime><storyTime>汉末</storyTime></detail></book><book category="小说" edition="2"><id>3</id><name>红楼梦</name><price>35</price><author>曹雪芹</author><detail><pressTime>清朝</pressTime><storyTime>不详</storyTime></detail></book><book category="神话小说" edition="4"><id>4</id><name>西游记</name><price>25</price><author>吴承恩</author><detail><pressTime>明朝</pressTime><storyTime>大唐</storyTime></detail></book><book category="小说" edition="5"><id>5</id><name>水浒传</name><price>30</price><author>施耐庵</author><detail><pressTime>明朝</pressTime><storyTime>大宋</storyTime></detail></book>
</books>

1.把所有的edition属性的值为8的修改为100
使用xpath查找对象时,依赖于jaxen.jar包,所以要先下载这个包。查找对象时,如果查找的是节点,直接写名称,如:/books/book/name,如果查找的是属性,要在属性前加上@,如:/books/book/@edition

    @Testpublic void modifyXmlFile(){try {SAXReader reader = new SAXReader();Document document = reader.read(new File("F:\\test\\books.xml"));//先利用xpath查找对象List<Node> ns = document.selectNodes("/books/book/@edition");Iterator<Node> iter = ns.iterator();while(iter.hasNext()){Attribute attr = (Attribute) iter.next();if(Integer.parseInt(attr.getValue())==8){attr.setValue("100");}}//输出修改后的文件PrintWriter out = new PrintWriter(new File("F:\\test\\m1.xml"));XMLWriter w = new XMLWriter(out,OutputFormat.createPrettyPrint());w.write(document);w.close();} catch (DocumentException e) {e.printStackTrace();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} }

2.把“Java编程思想”修改为“Java语言程序设计”并在该name属性所在的book节点中添加buyTime节点,节点值为2015-04-27:

    @Testpublic void modifyXmlFile(){try {SAXReader reader = new SAXReader();Document document = reader.read(new File("F:\\test\\books.xml"));//先利用xpath查找对象List<Node> ns = document.selectNodes("/books/book/name");Iterator<Node> iter = ns.iterator();while(iter.hasNext()){Element e = (Element) iter.next();if(e.getText().equals("Java编程思想")){e.setText("Java语言程序设计");Element pe = e.getParent();Element new_e = pe.addElement("buyTime");new_e.setText("2015-04-27");}}//输出修改后的文件PrintWriter out = new PrintWriter(new File("F:\\test\\m2.xml"));XMLWriter w = new XMLWriter(out,OutputFormat.createPrettyPrint());w.write(document);w.close();} catch (DocumentException e) {e.printStackTrace();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} }

3.若edition属性值为8,则删除该属性

    @Testpublic void modifyXmlFile(){try {SAXReader reader = new SAXReader();Document document = reader.read(new File("F:\\test\\books.xml"));List<Node> ns = document.selectNodes("/books/book/@edition");Iterator<Node> iter = ns.iterator();while(iter.hasNext()){Attribute attr = (Attribute) iter.next();if(Integer.parseInt(attr.getValue())==8){attr.getParent().remove(attr);}}try {PrintWriter out = new PrintWriter(new File("F:\\test\\m3.xml"));XMLWriter w = new XMLWriter(out,OutputFormat.createPrettyPrint());w.write(document);w.close();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}} catch (DocumentException e) {e.printStackTrace();}}

4.把id为3的书的name节点删除:

@Test
public void modifyXmlFile(){try {SAXReader reader = new SAXReader();Document document = reader.read(new File("F:\\test\\books.xml"));List<Node> ns = document.selectNodes("/books/book/id");Iterator<Node> iter = ns.iterator();while(iter.hasNext()){Element e = (Element) iter.next();if(e.getText().equals("3")){e.getParent().remove(e.getParent().element("name"));}}PrintWriter out = new PrintWriter(new File("F:\\test\\m4.xml"));XMLWriter w = new XMLWriter(out, OutputFormat.createPrettyPrint());w.write(document);w.close();} catch (DocumentException e) {e.printStackTrace();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}

5.移除所有文件的id属性:

方式一:
直接查找id节点,再删除

    @Testpublic void modifyXmlFile(){try {SAXReader reader = new SAXReader();Document document = reader.read(new File("F:\\test\\books.xml"));List<Node> ns = document.selectNodes("/books/book/id");Iterator<Node> iter = ns.iterator();while(iter.hasNext()){Element e = (Element) iter.next();e.getParent().remove(e);}PrintWriter out = new PrintWriter(new File("F:\\test\\m5.xml"));XMLWriter w = new XMLWriter(out,OutputFormat.createPrettyPrint());w.write(document);w.close();} catch (DocumentException e) {e.printStackTrace();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}

方法二:
查找book节点,再删除book节点的id节点:

    @Testpublic void modifyXmlFile(){try {SAXReader reader = new SAXReader();Document document = reader.read(new File("F:\\test\\books.xml"));List<Node> ns = document.selectNodes("/books/book");Iterator<Node> iter = ns.iterator();while(iter.hasNext()){Element e = (Element) iter.next();e.remove(e.element("id"));}PrintWriter out = new PrintWriter(new File("F:\\test\\m6.xml"));XMLWriter w = new XMLWriter(out,OutputFormat.createPrettyPrint());w.write(document);w.close();} catch (DocumentException e) {e.printStackTrace();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}

好了,先写这么多,这些东东基本上够项目使用了。

转载于:https://www.cnblogs.com/qitian1/p/6461875.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/273291.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

交叉连接(CROSS JOIN)的实际应用

一次偶然的机会&#xff0c;使用到了万年不用的交叉连接&#xff08;CROSS JOIN&#xff09; 业务场景如下&#xff1a; 1、存在多个运营商&#xff0c;每个运营商下面都有各种类型的设备&#xff0c;不同运营商的设备不完全相同&#xff1b; 2、任何设备有且仅有两种用途‘…

Atitit.操作注册表 树形数据库 注册表的历史 java版本类库总结

Atitit.操作注册表 树形数据库 注册表的历史 java版本类库总结 1. 注册表是树形数据库 1 2. 注册表的由来 1 3. Java 操作注册表 2 3.1. 使用Preferences API &#xff08;限定访问路径了&#xff09; 2 3.2. 使用JNI 3 3.3. Jregistrykey 推荐 4 3.4. Jregistry 4 4. org.ope…

C# xml文件读取与修改

c#读写xml文件已知有一个XML文件&#xff08;bookstore.xml&#xff09;如下&#xff1a; Code<?xml version"1.0" encoding"gb2312"?><bookstore> <book genre"fantasy" ISBN"2-3631-4"> <title>Obero…

外连接从表过滤

1、使用left join时从表的过滤 WITH a AS( SELECT A aid FROM dual UNION ALL SELECT B FROM dual UNION ALL SELECT C FROM dual UNION ALL SELECT D FROM dual UNION ALL SELECT E FROM dual ), b AS( SELECT A aid,10 num,1 type FROM dual UNION ALL SELECT B,20,2 FROM d…

php pcntl 多进程学习

1、捕获子进程退出&#xff08;监听SIGCHLD信号&#xff0c;然后调用 pcntl_wait 函数&#xff09; declare(ticks1);pcntl_signal(SIGCHLD, "sig_handler"); function sig_handler($signo) {switch ($signo) {case SIGCHLD:$status 0;$child_id pcntl_wait($statu…

Oracle取最大/最小值函数

SELECT greatest(DATE2020-01-01,DATE2020-01-03,DATE2020-01-05,DATE2020-01-07,DATE2020-01-09) 最大值, least(1,3,5,7,9) 最小值 FROM dual; SELECT 1 FROM dual WHERE greatest(1,3,5,7,9) > 8;

ORACLE将查询字段指定为某种类型

SELECT CAST(张三 AS VARCHAR2(20)) name FROM dual; 一般来说在查询时很少有用到这种语句&#xff0c;但是使用CREATE TABLE ... AS SELECT ...语句的时候这个就很好用了 --建表 CREATE TABLE test01 AS SELECT 张三 name FROM dual; --正常插入数据 INSERT INTO test01 SEL…

Less Css 教程

http://www.w3cplus.com/css/less&#xff0c;这个东西太吊了&#xff01;转载于:https://www.cnblogs.com/wln3344/p/4479014.html

分组查询最晚一条数据(ORACLE)

现有客户表&#xff0c;交费表&#xff0c;需查询每个存在交费记录客户的最后一笔交费信息 这里提供两种方式 注&#xff1a;客户不会在同一时间有两条交费&#xff0c;SQL可直接执行 --查询客户名称&#xff0c;最后一笔交费时间&#xff0c;以及最后一笔交费金额 WITH --客…

ORACLE循环中使用序列

在批量生成数据时&#xff0c;经常会用到序列的Nextval&#xff0c;今天碰到了这样的情况&#xff0c;日常记录&#xff0c;下附解决方案。先看这段脚本 DECLARE i INTEGER; BEGINFOR cur IN 1..5 LOOPi : DomainObjectId.Nextval;dbms_output.put_line(i);END LOOP; END; 编…

常用的机器学习数据挖掘知识点【转】

转自&#xff1a; 【基础】常用的机器学习&数据挖掘知识点 Basis(基础)&#xff1a; MSE(Mean Square Error 均方误差)&#xff0c;LMS(LeastMean Square 最小均方)&#xff0c;LSM(Least Square Methods 最小二乘法)&#xff0c;MLE(MaximumLikelihood Estimation最大似然…

tomcat运行问题解决方法

早上过来遇到一个非常奇怪的问题&#xff0c;运行一个新的项目&#xff0c;运行环境都没问题&#xff0c;可是在调试的时候&#xff0c;总是出错。 错误代码&#xff1a; log4j:WARN No appenders could be found for logger log4j:WARN Please initialize the log4j system p…

团队开发——冲刺1.d

冲刺阶段一&#xff08;第四天&#xff09; 1、昨天做了什么&#xff1f; 完成部分界面设置&#xff0c;补充三层难度界面、游戏结束界面。 2、今天准备做什么&#xff1f; 优化界面细节。查看C#资料&#xff0c;再解决自己电脑的问题。 3、遇到什么困难&#xff1f; 已经固定好…

10. javacript高级程序设计-DOM

1. DOM DOM(文档对象模型)是针对HTML和XML文档的一个API&#xff08;应用程序接口&#xff09; 1.1 节点层次 DOM可以将任何HTML和XML文档描绘成一个由多层节点构成的结构。节点分为几种不同的类型&#xff0c;每种类型分别表示文档中不同的信息及标记。 1.1.1 Node类型 DOM1中…

hdu 5045 Contest(状态压缩DP)

题解&#xff1a;我们使用一个二位数组dp[i][j]记录进行到第i个任务时&#xff0c;人组合为j时的最大和&#xff08;这里的j我们用二进制的每位相应一个人&#xff09;。 详细见代码&#xff1a; #include <iostream> #include <cstdio> #include <cstring> …

mysql001创建数据库

-- 注释&#xff0c;ctrl/ -- 查询所有数据库&#xff1b; show DATABASES; -- 创建数据库; CREATE DATABASE studb; -- 切换数据库; USE studb; -- 删除数据库 DROP DATABASE studb;

mysql002创建表

-- 创建student表 DDL CREATE TABLE stdent( sno int(3), name VARCHAR(55), sex CHAR(2), age int, dtdate date, classname VARCHAR(55), email VARCHAR(55) ) -- 查询表中数据 DQL SELECT * FROM stdent;

oc基础-self关键字的使用

#import <Foundation/Foundation.h>interface Student : NSObject {int _age;char *_name; } - (void) study; - (void) run; (void) play;(void) run; endimplementation Student - (void) study {NSLog("%s在学习",self->_name);[self run];//若在此调用…

mysql003操作表DDL

-- 查询表中数据 DQL 注意在mydb数据库下面 SELECT * FROM stdent; -- 在表中添加一列 DDL -- 新增列 默认添加到最后 ALTER TABLE stdent add score DOUBLE(4,1); -- 新增一列 在表中开头添加 ALTER TABLE stdent add score2 double(5,1) first; -- 在指定列后面添…

Google Guava学习笔记——基础工具类Joiner的使用

Guava 中有一些基础的工具类&#xff0c;如下所列&#xff1a; 1&#xff0c;Joiner 类&#xff1a;根据给定的分隔符把字符串连接到一起。MapJoiner 执行相同的操作&#xff0c;但是针对 Map 的 key 和 value。 2&#xff0c;Splitter 类&#xff1a;与 Joiner 操作相反的类&a…