ml基础教程课后习题解答.docx
《ml基础教程课后习题解答.docx》由会员分享,可在线阅读,更多相关《ml基础教程课后习题解答.docx(14页珍藏版)》请在冰豆网上搜索。
ml基础教程课后习题解答
内部编号:
(YUUT-TBBY-MMUT-URRUY-UOOY-DBUYI-0128)
XML基础教程课后习题解答
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文档类型声明的格式:
DOCTYPE根标记的名称PUBLIC"正式公用标识符""DTD文件的URI">
5.答:
一定。
6.答:
(1)约束标记“张三”必须有“学号”属性
(2)约束标记“张三”必须有“学号”属性,而且学号的属性值是固定的220123。
(3)约束标记“张三”可以有也可以没有“学号”属性。
7.答:
ID类型的属性的属性值具有互斥性,即所有ID类型的属性的属性值必须互不相同。
8.答:
不合理。
9.答:
(1)、(3)和(4)。
10.答,不是有效的。
将修改为有效:
DOCTYPE成绩单SYSTEM"">
<成绩单>
<学生>
<姓名>张三姓名>
<成绩>优秀成绩>
学生>
<学生>
<姓名>李四姓名>
<成绩>良好成绩>
学生>
成绩单>
习题四
1.答:
一个返回子孙节点,而另一个只返回子节点:
(1)getElementsByTagName(Stringname):
返回一个NodeList对象,该对象由当前节点的Element类型子孙节点组成,这些子孙节点的名字由参数name指定
(2)getChildNodes():
节点调用该方法返回一个由当前节点的所有子节点组成的NodeList对象。
2.答:
分别是DocumentType类型和Element类型。
3.
import3c
import.*;
publicclassJAXPXiti5
{
publicstaticvoidmain(Stringargs[])
{
OutResultoutContent=newOutResult();
try{
DocumentBuilderFactoryfactory=
DocumentBuilderFactory.newInstance();
DocumentBuilderbuilder=factory.newDocumentBuilder();
Documentdocument=builder.parse(newFile(""));
Elementroot=();
StringrootName=();
NodeListnodeList=();
(nodeList);
}
catch(Exceptione)
{
}
}
}
classOutResult
{
doublesumAllMath,sumAllPhysics,mathAver,physicsAver;
intmathNumber=0,physicsNumber=0;
publicvoidoutput(NodeListnodeList)
{
intsize=();
for(intk=0;k{
Nodenode=(k);
if()==
{
TexttextNode=(Text)node;
Stringcontent=();
Elementparent=(Element)();
if().equals("数学"))
{
mathNumber++;
sumAllMath=sumAllMath+());
}
if().equals("物理"))
{
physicsNumber++;
sumAllPhysics=sumAllPhysics+());
}
}
if()==
{
ElementelementNode=(Element)node;
Stringname=();
NodeListnodes=();
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.答:
import3c
import.*;
publicclassXiti7
{
publicstaticvoidmain(Stringargs[])
{
OutTotaloutWeight=newOutTotal();
try{
DocumentBuilderFactoryfactory=DocumentBuilderFactory.newInstance();
DocumentBuilderbuilder=factory.newDocumentBuilder();
Documentdocument=(newFile(""));
Elementroot=();
NodeListnodeList=();
(nodeList);
}
catch(Exceptione){
}
}
}
classOutTotal
{
doublesum;
publicvoidoutput(NodeListnodeList)
{
intsize=();
for(intk=0;k{
Nodenode=(k);
if()==
{
TexttextNode=(Text)node;
Stringcontent=();
Elementparent=(Element)();
if().equals("重量"))
sum=sum+());}
if()==
{
ElementelementNode=(Element)node;
Stringname=();
NodeListnodes=();
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.答:
import3c
publicclassXiti8{
publicstaticvoidmain(Stringargs[]){
try{XPathFactoryxPathFactory=();
XPathxPath=();
InputSourcesource=newInputSource("");
StringcountPath="count(/货品列表/货品/重量)";
StringsumPath="sum(/货品列表/货品/重量)";
Doublesum=(Double)(sumPath,source,;
doubletotal=();
}
catch(Exceptionexp){
}
}
}
5.答:
<学生列表>
<姓名>张三姓名>
<性别>男性别>
<年龄>29年龄>
学生>
<姓名>李张林姓名>
<性别>男性别>
<年龄>18年龄>
学生>
<学生学号='000'>
<姓名>张李号姓名>
<性别>女性别>
<年龄>25年龄>
学生>
学生列表>
publicclassApplication{
publicstaticvoidmain(Stringargs[]){
newStudentConditionWindow();
}
}
import.*;
import.*;
publicclassStudentConditionWindowextendsJFrame{
JTextFieldinputName,inputNumber;
JTextAreashowResult;
JButtonbutton;
BoxbaseBox,boxV1,boxV2;
StudentConditionWindow(){
inputName=newJTextField(10);
inputNumber=newJTextField(10);
boxV1=();
(newLabel("姓名中包含:
"));
(newLabel("学号中包含"));
boxV2=();
(inputName);
(inputNumber);
baseBox=();
(boxV1);
(boxV2);
JPanelwest=newJPanel();
(baseBox);
button=newJButton("确定");
(button);
add(west,;
showResult=newJTextArea(10,10);
(newFont("宋体",,12));
add(newJScrollPane(showResult),;
FindStudentByXPathfindStudent;3c;
publicclassFindStudentByXPathimplementsActionListener{
XPathFactoryxPathFactory;
XPathxPath;
StringpositionPath;
InputSourcesource;
JTextFieldinputName,inputNumber;
JTextAreashowResult;
FindStudentByXPath(JTextFieldinputName,JTextFieldinputNumber,JTextAreashowResult,StringfileName){
=inputName;
=inputNumber;
=showResult;
xPathFactory=();
xPath=();
source=newInputSource(fileName);
=positionPath;
}
publicvoidactionPerformed(ActionEvente){
(null);
StringstudentName=().trim();
StringstudentNumber=().trim();
Stringpredicates="[contains(姓名,'"+studentName+"')and"+
"contains(@学号,'"+studentNumber+"')]";
Stringpath="/学生列表/学生"+predicates+"/*";18pt10pt10pt12pt12pt8pt答:
<雇员列表>
<雇员>
<姓名>张三姓名>
<月薪>月薪>
<参加工作时间>2000-12-12参加工作时间>
雇员>
<雇员>
<姓名>李四姓名>
<月薪>月薪>
<参加工作时间>2001-10-28参加工作时间>
雇员>
雇员列表>
elementname="雇员列表">
complexType>
sequence>
elementref="雇员"minOccurs="1"maxOccurs="12089"/>
sequence>
complexType>
element>
elementname="雇员">
complexType>
sequence>
elementref="姓名"/>
elementref="月薪"/>
elementref="参加工作时间"/>
sequence>
complexType>
element>
elementname="姓名"type="xsd:
string"/>
elementname="参加工作时间"type="xsd:
date"/>
--对始发时间标记的约束-->
elementname="月薪"type="xsd:
float"/>
--对车厢数目标记的约束-->
schema>