搜档网
当前位置:搜档网 › ml基础教程课后习题解答

ml基础教程课后习题解答

ml基础教程课后习题解答
ml基础教程课后习题解答

X M L基础教程课后习

题解答

内部编号:(YUUT-TBBY-MMUT-URRUY-UOOY-DBUYI-0128)

XML基础教程课后习题

习题一

1.答:HTML是用来编写Web页的语言、不允许用户自定义标记,HTML体现数据的显示格式。XML描述数据的组织结构、可自定义标记,其标记名称是对标记所包含的数据内容含义的抽象,而不是数据的显示格式。

2.答:使用UTF-8保存

5.答:(1)不可以,(2)可以,(3)不可以

6.答::

time

{ display:block;font-size:18pt;font-weight:bold

}

hour

{ display:line;font-size:16pt;font-style:italic

}

mimute

{ display:line;font-size:9pt;font-weight:bold

}

习题二1.答:(1)使用ANSI编码。(2)可以。(3)不合理。

2.答:不相同。

3.答:(1)和(2)。

4.答:。

5.答:“root”标记包含的文本内容都是空白字符。“a1”标记包含的文本内容:。“a2”标记包含的文本内容: 子曰"有朋自远方来,不亦乐乎"。

习题三1.答:一个规范的XML文件如果和某个DTD文件相关联,并遵守该DTD文件规定的约束条件,就称之为有效的XML文件。

2.答:DTD文件的编码必须和其约束的XML文件的编码相一致。

3.答:无关。

4.答:(1) 使用SYSTEM文档类型声明的格式:

(2) 使用PUBLIC文档类型声明的格式:

5.答:一定。

6.答:(1)约束标记“张三”必须有“学号”属性

(2)约束标记“张三”必须有“学号”属性,而且学号的属性值是固定的220123。

(3)约束标记“张三”可以有也可以没有“学号”属性。

7.答:ID类型的属性的属性值具有互斥性,即所有ID类型的属性的属性值必须互不相同。

8.答:不合理。

9.答:(1)、(3)和(4)。

10.答,不是有效的。将修改为有效:

<成绩单>

<学生>

<姓名> 张三

<成绩> 优秀

<学生>

<姓名> 李四

<成绩> 良好

习题四

1.答:一个返回子孙节点,而另一个只返回子节点:(1)getElementsByTagName(String name):返回一个NodeList对象,该对象由当前节点的Element类型子孙节点组成,这些子孙节点的名字由参数name指定(2)getChildNodes():节点调用该方法返回一个由当前节点的所有子节点组成的NodeList对象。

2.答:分别是DocumentType类型和Element类型。

3.

import 3c

import .*;

public class JAXPXiti5

{

public static void main(String args[])

{

OutResult outContent=new OutResult();

try {

DocumentBuilderFactory factory=

DocumentBuilderFactory. newInstance();

DocumentBuilder builder= factory. newDocumentBuilder();

Document document= builder. parse(new File("")) ;

Element root=() ;

String rootName=();

NodeList nodeList=();

(nodeList);

}

catch(Exception e)

{

}

}

}

class OutResult

{

double sumAllMath,sumAllPhysics,mathAver,physicsAver;

int mathNumber=0, physicsNumber=0;

public void output(NodeList nodeList)

{

int size=();

for(int k=0;k

{

Node node=(k);

if()==

{

Text textNode=(Text)node;

String content=();

Element parent=(Element)();

if().equals("数学"))

{

mathNumber++;

sumAllMath=sumAllMath+());

}

if().equals("物理"))

{

physicsNumber++;

sumAllPhysics=sumAllPhysics+());

}

}

if()==

{

Element elementNode=(Element)node;

String name=();

NodeList nodes=();

output(nodes);

}

}

mathAver=sumAllMath/mathNumber;

physicsAver=sumAllPhysics/physicsNumber;

}

}

习题五:DOM解析器的核心是在内存中建立和XML文件相对应的树形结构数据,如果XML文件较大,相应的Document对象就要占用较多的内存空间;SAX解析器不在内存中建立和XML文件相对应的树形结构数据,和DOM解析器相比,SAX解析器占有的内存少。

1.答:不报告。(这个答案不知道)

2.答:uri和localName的取值是空字符组成的串,即uri="",localName="",参数qName取值是标记名称,atts是标记的所有属性的集合。

3.答:当忽略标记之间形成的空白区域时。

4.答:

import 3c

import .*;

public class Xiti7

{

public static void main(String args[])

{

OutTotal outWeight=new OutTotal();

try {

DocumentBuilderFactory

factory=DocumentBuilderFactory. newInstance();

DocumentBuilder builder= factory.

newDocumentBuilder();

Document document= (new File("")) ; Element root=() ;

NodeList nodeList=();

(nodeList);

}

catch(Exception e) {

}

}

}

class OutTotal

{

double sum;

public void output(NodeList nodeList)

{

int size=();

for(int k=0;k

{

Node node=(k);

if()==

{

Text textNode=(Text)node;

String content=();

Element parent=(Element)();

if().equals("重量"))

sum=sum+()); }

if()==

{

Element elementNode=(Element)node;

String name=();

NodeList nodes=();

output(nodes);

}

}

}

}

习题六1.答:Element类型节点对应XML中的标记。

2.答:

(1)按顺序对应着第一个名字是“教室”的标记中的第一个名字是“桌子”标记的“价格”标记。

(2) 对应着具有属性number,属性值是02、名字为“桌子”的标记,而且这些桌子标记有子标记“价格”,而且价格包含的文本是数字且值大于等于360。

(3)对应“教室”的属性。

(4)number属性所在的“教室”节点。

(5)109

(6)396,267

(7)对应着“教室”标记,具教室标记有孙标记“价格”,且“价格”标记含有的数字文本的值大于390,即是第2个“教室”标记。

(8)对应着价格标记,且“价格”标记含有的数字文本的值大于396。3.答:

(1)【结果1】: A1001定单的总额:

(2)【结果2】:

(3)【结果3】: 4

(4)【结果4】:100

4.答:

import 3c

public class Xiti8{

public static void main(String args[]){

try{ XPathFactory xPathFactory=();

XPath xPath=();

InputSource source=new InputSource("");

String countPath="count(/货品列表/货品/重量)";

String sumPath="sum(/货品列表/货品/重量)";

Double sum=(Double)(sumPath,source,;

double total=();

}

catch(Exception exp){

}

}

}

5.答:

<学生列表>

<姓名>张三

<性别> 男

<年龄> 29

<姓名>李张林

<性别> 男

<年龄> 18

<学生学号='000'>

<姓名>张李号

<性别> 女

<年龄> 25

public class Application{

public static void main(String args[]){

new StudentConditionWindow();

}

}

import .*;

import .*;

public class StudentConditionWindow extends JFrame { JTextField inputName,inputNumber;

JTextArea showResult;

JButton button;

Box baseBox ,boxV1,boxV2;

StudentConditionWindow(){

inputName=new JTextField(10);

inputNumber=new JTextField(10);

boxV1=();

(new Label("姓名中包含:"));

(new Label("学号中包含"));

boxV2=();

(inputName);

(inputNumber);

baseBox=();

(boxV1);

JPanel west=new JPanel();

(baseBox);

button=new JButton("确定");

(button);

add(west,;

showResult=new JTextArea(10,10);

(new Font("宋体",,12));

add(new JScrollPane(showResult),;

FindStudentByXPath findStudent; 3c;

public class FindStudentByXPath implements ActionListener { XPathFactory xPathFactory;

XPath xPath;

String positionPath;

InputSource source;

JTextField inputName,inputNumber;

JTextArea showResult;

FindStudentByXPath(JTextField inputName,JTextField inputNumber,JTextArea showResult,String fileName){ =inputName;

=inputNumber;

=showResult;

xPathFactory=();

source=new InputSource(fileName);

=positionPath;

}

public void actionPerformed(ActionEvent e){

(null);

String studentName=().trim();

String studentNumber=().trim();

String predicates="[contains(姓名,'"+studentName+"') and "+

"contains(@学号,'"+studentNumber+"')]"; String path="/学生列表/学生"+predicates+"/*";

18pt10pt10pt12pt12pt8pt答:

<雇员列表>

<雇员>

<姓名>张三

<月薪>

<参加工作时间>2000-12-12

<雇员>

<姓名>李四

<月薪>

<参加工作时间>2001-10-28

相关主题