版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
填空題:
答案〔答案僅供參考〕第一章1、Internet中的數(shù)據(jù)傳輸 2、SGML 3、電子數(shù)據(jù)交換4、HTML 選擇題:1、C 2、ABCD 3、ABCD 4、ABCD 5、ABCD簡(jiǎn)答題:1、答:XML〔ExtensibleMarkupLanguage,可擴(kuò)展的標(biāo)記語(yǔ)言〕是一套定義語(yǔ)標(biāo)記語(yǔ)言,可以定義其他與特定領(lǐng)域有關(guān)的、語(yǔ)義的、構(gòu)造化的標(biāo)記。,XML低本錢(qián),XMLVAN定制商業(yè)規(guī)章,XMLXML3、答:XML更有意義的搜尋。XML,搜尋軟件必需了解每個(gè)數(shù)據(jù)庫(kù)是如XML,狀況就完全不同了。例如,學(xué)生信息可以依據(jù)學(xué)號(hào)、姓名或其他的標(biāo)準(zhǔn)分類。這樣搜尋就變得格外便利。Web數(shù)據(jù)一旦建立,XMLXMLHTML、腳本、公共對(duì)象模Web不同來(lái)源數(shù)據(jù)的集成?,F(xiàn)在搜尋多樣的不兼容的數(shù)據(jù)庫(kù)實(shí)際上是不行能的。XML器上做進(jìn)一步的集成、處理和分發(fā)。多種應(yīng)用得到的數(shù)據(jù)。XMLWeb述就能被交換和處理。本地計(jì)算和處理。XML和處理。使用者可以用不同的方法處理數(shù)據(jù),而不僅僅是顯示它。XMLWeb創(chuàng)立功能強(qiáng)大的應(yīng)用軟件,這些軟件原來(lái)只能建立在高端數(shù)據(jù)庫(kù)上。數(shù)據(jù)的多樣顯示。數(shù)據(jù)發(fā)到桌面后,能夠用多種方式顯示。通過(guò)以簡(jiǎn)潔、開(kāi)放、擴(kuò)展的方式描述結(jié)XMLCSSXSL了統(tǒng)一且標(biāo)準(zhǔn)的機(jī)制。粒狀的更。XML,數(shù)據(jù)可以進(jìn)展粒狀的更。每當(dāng)一局部數(shù)據(jù)變化后,不需要重發(fā)整個(gè)整個(gè)使用者的界面就能夠顯示出來(lái)。WebHTML送,不需要對(duì)現(xiàn)存的網(wǎng)絡(luò)進(jìn)展轉(zhuǎn)變。升級(jí)性。掃瞄器的響應(yīng)時(shí)間。另外,XML了效勞器的工作量,大大增加了效勞器的升級(jí)性能。壓縮性。XML壓縮不僅要依據(jù)應(yīng)用來(lái)定,還取決于效勞器與客戶間數(shù)據(jù)的傳送量。其次章填空題:標(biāo)記5、空元素僅含子元素的元素選擇題:1、B2、A3、C4、B5、A簡(jiǎn)答題:1、答:規(guī)章1:必需有XML2:留意大小寫(xiě);規(guī)章3:全部的XML8:9:處理特別字符。2、答:XML1、元素的名字可以包含子母,數(shù)字和其他字符。2、元素的名字不能以數(shù)字或者標(biāo)點(diǎn)符號(hào)開(kāi)頭。3XML(xml,Xml,xMl...)開(kāi)頭。4、元素的名字不能包含空格。5而<the_title_of_the_book>則顯得啰嗦了。7XMLXML8/字符/XML盡量使用英文字母來(lái)進(jìn)展命名。XML字符。1、<?xmlversion=“1.0“encoding=“gb2312“?><book><title>XML指南</title><chapter>XML<para>HTML</para><para>XML</para></chapter><chapter>XML<para>XML元素必需有完畢標(biāo)簽</para><para>XML元素必需正確的嵌套</para></chapter></book>2、<?xmlversion=“1.0“encoding=“gb2312“?><employees><employee><id>1</id><name>張三</name><age>32</age><sex>男</sex><address>上海</address></employee><employee><id>2</id><name>李四</name><age>22</age><sex>男</sex><address>北京</address></employee></employees>3、<?xmlversion=“1.0“encoding=“gb2312“?><students><student><number>1</number><name>tom</name><score>100</score></student><student><number>2</number><name>mary</name><score>98</score></student></students>填空題:
第三章1XML文檔的構(gòu)造 2關(guān)鍵字文檔的根元素名稱可選的標(biāo)記聲明塊3ELEMENT45選擇題:1、A 2、C 3、A 4、A 上機(jī)題1、<?xmlversion=“1.0“encoding=“GB2312“?><!ELEMENT<!ELEMENT<!ELEMENT姓名(#PCDATA)><!ELEMENT性別(#PCDATA)><!ELEMENT年齡(#PCDATA)><!ATTLIST學(xué)生學(xué)號(hào)ID #REQUIRED>2、<?xmlversion=“1.0“encoding=“UTF-8“?><NEWSPAPER><ARTICLE EDITION=”©RIGHT;”><HEADLINE>EnvironmentProtection</HEADLINE><BYLINE>Materialwaste</BYLINE><LEAD>&PUBLISHER;</LEAD><BODY>itmeansthewasteofsubstanceorthingsfromwhichsomethingelsecanbemade.Forexample,peoplethrowawaytheusedmetalproductsandbuyanewone,sotheoldmetalwasteaccumulates.Atlast,theybecomewaste.Forexample,whenpeoplefinishreadingnewspaper,thepaperwillbecomewaste.Whentheglassisbroken,italsobecomeswaste.Nobodywantstouseabrokenwindowordrinkwithabrokenglassorwearapairofbrokenglasses.Onceitisbroken,itbecomeswaste.Therateofusingplasticsisincreasingdaybyday.Peopleuseplasticbagsbecausetheyareconvenient.Whentheygethome,theythrowtheplasticsway,payingnoattentiontotheenvironment.Themoreconvenienceplasticsbringstous,themoreplasticwasteisproduced.Thisiscalled“whitepollution”asmostplasticsarewhite.Someofourproductsweuseeverydayaremadeofrubber,justlikethetyresandthebottompartofourshoes.It’struethatrubberplaysanimportantroleinourlife.However,italsobringsussometroublewhenithasbeenusedforalongtimeandbecomesold.Theabigproblem.</BODY><NOTES>Protectingtheenvironmentisnotoneperson’sduty;itdependsonallofus.Whatcanwedo?Maybeadozen..canreuseasmuchaspossible.Remember,environmentprotectionisnotone’sduty!</NOTES></ARTICLE></NEWSPAPER>3、<?xmlversion=“1.0“encoding=“UTF-8“?><!DOCTYPENEWSPAPER[<!ELEMENTNEWSPAPER(ARTICLE+)><!ELEMENTARTICLE(HEADLINE,BYLINE,LEAD,BODY,NOTES)><!ELEMENTHEADLINE(#PCDATA)><!ELEMENTBYLINE(#PCDATA)><!ELEMENTLEAD(#PCDATA)><!ELEMENTBODY(#PCDATA)><!ELEMENTNOTES(#PCDATA)><!ATTLISTARTICLEAUTHORCDATA#REQUIRED><!ATTLISTARTICLEEDITORCDATA#IMPLIED><!ATTLISTARTICLEDATECDATA#IMPLIED><!ATTLISTARTICLEEDITIONCDATA#IMPLIED><!ENTITYNEWSPAPER“VervetLogicTimes“><!ENTITYPUBLISHER“VervetLogicPress“><!ENTITY]>COPYRIGHT“Copyright1998VervetLogicPress“><NEWSPAPER><ARTICLE EDITION=”©RIGHT;”><HEADLINE>EnvironmentProtection</HEADLINE><BYLINE>Materialwaste</BYLINE><LEAD>&PUBLISHER;</LEAD><BODY>itmeansthewasteofsubstanceorthingsfromwhichsomethingelsecanbemade.Forexample,peoplethrowawaytheusedmetalproductsandbuyanewone,sotheoldmetalwasteaccumulates.Atlast,theybecomewaste.Forexample,whenpeoplefinishreadingnewspaper,thepaperwillbecomewaste.Whentheglassisbroken,italsobecomeswaste.Nobodywantstouseabrokenwindowordrinkwithabrokenglassorwearapairofbrokenglasses.Onceitisbroken,itbecomeswaste.Therateofusingplasticsisincreasingdaybyday.Peopleuseplasticbagsbecausetheyareconvenient.Whentheygethome,theythrowtheplasticsway,payingnoattentiontotheenvironment.Themoreconvenienceplasticsbringstous,themoreplasticwasteisproduced.Thisiscalled“whitepollution”asmostplasticsarewhite.Someofourproductsweuseeverydayaremadeofrubber,justlikethetyresandthebottompartofourshoes.It’struethatrubberplaysanimportantroleinourlife.However,italsobringsussometroublewhenithasbeenusedforalongtimeandbecomesold.Theabigproblem.</BODY><NOTES>Protectingtheenvironmentisnotoneperson’sduty;itdependsonallofus.Whatcanwedo?Maybeadozen..canreuseasmuchaspossible.Remember,environmentprotectionisnotone’sduty!</NOTES></ARTICLE></NEWSPAPER>第四章填空題:“:///2001/XMLSchema“:///2001/XMLSchema5XML次數(shù)選擇題:1、C 2、A 3、A 4、A 上機(jī)題1、<?xmlversion=“1.0“encoding=“UTF-8“?><xs:schema“:///2001/XMLSchema“xmlns:xs=“:///2001/XMLSchema“><xs:elementname=“Orders“type=“ord“/><xs:complexTypename=“ord“><xs:elementname=“Order“><xs:complexType><xs:sequence><xs:elementname=“name“type=“xs:string“/><xs:elementname=“number“type=“numgs“/><xs:elementname=“city“type=“xs:string“/><xs:elementname=“zip“type=“zipgs“/></xs:sequence><xs:attributename=“orderID“type=“idgs“use=“required“/><xs:attributename=“orderDate“type=“xs:date“use=“optional“/></xs:complexType></xs:element></xs:complexType><xs:simpleTypename=“zipgs”><xs:restrictionbase=“xs:string”><xs:lengthvalue=“6”/><xs:patternvalue=“\d{6}”/></xs:restriction></xs:simpleType><xs:simpleTypename=“idgs”><xs:restrictionbase=“xs:string”><xs:lengthvalue=“4”/><xs:patternvalue=“[A]{1}\d{3}”/></xs:restriction></xs:simpleType><xs:simpleTypename=“numgs”><xs:restrictionbase=“xs:positiveInteger”><xs:maxInclusivevalue=“99”/><xs:minInclusicevalue=“1”/></xs:restriction></xs:simpleType></xs:schema>2、<?xmlversion=“1.0“?><xsd:schema“:///2001/XMLSchema“xmlns:xsd=“:///2001/XMLSchema“><xsd:attributename=“PRODID“type=“pid“/><xsd:simpleTypename=“pid“><xsd:restrictionbase=“xsd:string“><xsd:patternvalue=“[P]{1}\d{3}“/></xsd:restriction></xsd:simpleType><xsd:elementname=“PRODUCTDATA“type=“prdata“/><xsd:complexTypename=“prdata“><xsd:sequence><xsd:elementname=“PRODUCT“><xsd:complexType><xsd:sequence><xsd:elementname=“PRODUCTNAME“type=“xsd:string“/><xsd:elementname=“DESCRIPTION“type=“xsd:string“/><xsd:elementname=“PRICE“type=“xsd:positiveInteger“/><xsd:elementname=“QUANTITY“type=“xsd:nonNegativeInteger“/></xsd:sequence><xsd:attributeref=“PRODID“use=“required“></xsd:attribute><xsd:attributename=“CATEGORY“type=“cat“use=“required“/></xsd:complexType></xsd:element></xsd:sequence></xsd:complexType><xsd:simpleTypename=“cat“><xsd:restrictionbase=“xsd:string“><xsd:enumerationvalue=“Toy“/><xsd:enumerationvalue=“Book“/></xsd:restriction></xsd:simpleType></xsd:schema>3、<?xmlversion=“1.0“encoding=“UTF-8“?><xs:schema“:///2001/XMLSchema“xmlns:xs=“:///2001/XMLSchema“><xs:elementname=“PURCHASEORDER“type=“pur“/><xs:complexTypename=“pur“><xs:elementname=“Order“><xs:complexType><xs:sequence><xs:elementname=“DATE“type=“xs:date“/><xs:elementname=“PRODUCTNAME“type=“xs:string“/><xs:elementname=“SUPPLIERNAME“type=“xs:string“/><xs:elementname=“ADDRESS“type=“xs:string“/><xs:elementname=“QUANTITY“type=“xs:positiveInteger“/><xs:elementname=“PRICEPERQTY“type=“xs:positiveInteger“/></xs:sequence></xs:complexType></xs:element><xs:attributename=“ORDERID“type=“xs:string“use=“required“/><xs:attributename=“PRODID“type=“xs:string“use=“optional“/></xs:complexType></xs:schema>第五章填空題:2、CSSXSL3XMLXML45、xsl:value-of選擇題:1、B 2、B 3、D 4、B 上機(jī)題1、、<?xmlversion=“1.0“encoding=“gb2312“?><xsl:stylesheet version=“1.0““:///1999/XSL/Transform“xmlns:xsl=“:///1999/XSL/Transform“><xsl:templatematch=“/“><html><head><title>訂單信息</title></head><body><h2align=“center“>訂單</h2><tableborder=“1“cellpadding=“0“align=“center“><tr><th></th><th></th><th></th><th></th></tr><xsl:for-eachselect=“/Orders/Order“><tr>
<td><xsl:value-ofselect=“name“/></td><td><xsl:value-ofselect=“number“/></td><td><xsl:value-ofselect=“city“/></td><td><xsl:value-ofselect=“zip“/></td></tr></xsl:for-each></table></body></html></xsl:template></xsl:stylesheet>、<?xmlversion=“1.0“encoding=“gb2312“?><xsl:stylesheet version=“1.0““:///1999/XSL/Transform“xmlns:xsl=“:///1999/XSL/Transform“><xsl:templatematch=“/“><html><head><title>訂單信息</title></head><body><h2align=“center“>訂單</h2><tableborder=“1“cellpadding=“0“align=“center“><tr><th></th><th></th><th></th><th></th></tr><xsl:iftest=“//Order[@orderID=”A002”]“><tr>
<td><xsl:value-ofselect=“name“/></td><td><xsl:value-ofselect=“number“/></td><td><xsl:value-ofselect=“city“/></td><td><xsl:value-ofselect=“zip“/></td></tr></xsl:if></table></body></html></xsl:template></xsl:stylesheet>、<?xmlversion=“1.0“encoding=“gb2312“?><xsl:stylesheet version=“1.0““:///1999/XSL/Transform“xmlns:xsl=“:///1999/XSL/Transform“><xsl:templatematch=“/“><html><head><title>訂單信息</title></head><body><h2align=“center“>訂單</h2><tableborder=“1“cellpadding=“0“align=“center“><tr><th></th><th></th><th></th><th></th></tr><xsl:iftest=“city[.=”北京”]“><tr>
<td><xsl:value-ofselect=“name“/></td><td><xsl:value-ofselect=“number“/></td><td><xsl:value-ofselect=“city“/></td><td><xsl:value-ofselect=“zip“/></td></tr></xsl:if></table></body></html></xsl:template></xsl:stylesheet>2、PRODUCTNAME{font-family:Arial;font-size:20pt;font-weight:bold;color:red;display:block;padding-top:6pt;padding-bottom:6pt}PRICE,DESCRIPTION,QUANTITY{font-family:Arial;font-size:10pt;color:green;display:block;padding-top:2pt;padding-bottom:2pt}3、<?xmlversion=“1.0“?><xsl:stylesheet “:///1999/XSL/Transform“version=“1.0“><xsl:templatematch=“/“><xsl:for-eachselect=“PRODUCTDATA/PRODUCT“><xsl:choose><xsl:whentest=“PRODUCTNAME“><fontcolor=“red“>產(chǎn)品名:<xsl:value-ofselect=“PRODUCTNAME“/><BR/></font></xsl:when><xsl:otherwise><fontcolor=“green“>描述:<xsl:value-ofselect=“DESCRIPTION“/><BR/>價(jià)格:<xsl:value-ofselect=“PRICE“/><BR/>現(xiàn)有量:<xsl:value-ofselect=“QUANTITY“/><BR/><BR/></font></xsl:otherwise></xsl:choose></xsl:for-each></xsl:template></xsl:stylesheet>第六章填空題:1、FORXML 2、RAW 3、AUTO 4、EXPLICIT 選擇題:1、B 2、AB 3、B 4、A 簡(jiǎn)答題:EXPLICIT或PATHsp_xml_preparedocumentOPENXMLsp_xml_preparedocumentXMLsp_xml_removedocumentXML1、IEURL“://localhost/XMLTest?sql=select%2B“://localhost/XMLTest?sql=select+*from+student+for+xml+RAW&root=root“://localhost/XMLTest?sql=select%2B“://localhost/XMLTest?sql=select+*from+student+for+xml+Auto&root=student2“bin“female“30XMLstudentDECLARE@docvarchar(1000)DECLARE@idocintSET@doc=”<ROOT><student><id>5</id><name>bin</name><sex>female</sex><age>30</age></student></ROOT>”execsp_xml_preparedocument@idocoutput,@docselect*fromopenxml(@idoc,”/ROOT/student”,2)with(idint,namevarchar(40),sexvarchar(20),ageint)insertstudentselect*fromopenxml(@idoc,”/ROOT/student”,2)withstudentexecsp_xml_removedocument@idoc3“bin“female“30XMLstudentUSEschoolDECLARE@docvarchar(1000)DECLARE@idocintSET@doc=”<ROOT><studentid=“6“name=“bin“sex=“female“age=“30“></student></ROOT>”execsp_xml_preparedocument@idocoutput,@docselect*fromopenxml(@idoc,”/ROOT/student”,1)with(idint,namevarchar(40),sexvarchar(20),ageint)insertstudentselect*fromopenxml(@idoc,”/ROOT/student”)withstudentexecsp_xml_removedocument@idoc第七章填空題:1、XLink XPointer 2、簡(jiǎn)潔的 可擴(kuò)展的3、simple 4、XPointer 置項(xiàng)選擇題:1、A 2、B 3、B 4、A 上機(jī)題1、<GOTOxlink:type=”simple”xlink:href=”“://baidu/“://baidu”xlink:title=”Address”xlink:show=”replace”xlink:actuate=”onRequest”>thisisaslinkedelement</GOTO>2、<GOTOxlink:type=”simple”xlink:href=”“://sina/“://sina”xlink:title=”Address”xlink:show=”new”xlink:actuate=”onRequest”>thisisaslinkedelement</GOTO>3、<?xmlversion=“1.0“encoding=“gb2312“?><library><bookname=“C#技術(shù)內(nèi)幕“id=“1101“><cover“:///book/cover01.jpg“url=“:///book/cover01.jpg“/><press>機(jī)械工業(yè)出版社</press><description>C#是一種嶄的面對(duì)對(duì)象的編程語(yǔ)言。它強(qiáng)調(diào)以組件為根底的軟件開(kāi)發(fā)方法。</description></book><bookname=“時(shí)間簡(jiǎn)史“id=“5105“><cover“:///book/cover51.jpg“url=“:///book/cover51.jpg“/><press>湖南科學(xué)技術(shù)出版社</press><description></description></book><bookname=“ASP.NETid=“1102“><cover“:///book/cover01.jpg“url=“:///book/cover01.jpg“/><press>機(jī)械工業(yè)出版社</press><description>這是一本ASP.NET編程語(yǔ)言的指南和參考書(shū)。</description></book><bookname=“Javaid=“1105“><cover“:///book/cover51.jpg“url=“:///book/cover51.jpg“/><press>湖南科學(xué)技術(shù)出版社</press><description>這是一本Java編程語(yǔ)言的指南和參考書(shū)。</description></book><bookname=“JavaMEid=“1105“><cover“:///book/cover51.jpg“url=“:///book/cover51.jpg“/><press>湖南科學(xué)技術(shù)出版社</press><description>這是一本JavaME編程語(yǔ)言的指南和參考書(shū)。</description></book></library><?xmlversion=“1.0“?><browse“:///1999/xlink“xmlns:xlink=“:///1999/xlink“><bookxlink:type=“simple““:///books.xml#xpointer(id(%271102%27))“xlink:href=“:///books.xml#xpointer(id(”1102”))“><descriptionxlink:type=“simple““:///book/cover01.jpg“xlink:href=“:///book/cover01.jpg“>ASP.NET</description></book></browse>第八章填空題:3、節(jié)點(diǎn)4、DOMDocument 選擇題:1、ABCD 2、B 3、D 4、C 5、A簡(jiǎn)答題:1、答:最常見(jiàn)的節(jié)點(diǎn)類型有:XML有來(lái)作為其子節(jié)點(diǎn)。元素節(jié)點(diǎn)還是可以有屬性的唯一類型的節(jié)點(diǎn)。節(jié)點(diǎn)、文本:文本節(jié)點(diǎn)是:文本。它可以包含很多信息或僅僅是空白。(4)、文檔〔根節(jié)點(diǎn)2、答:XML象和方法有:?jiǎn)T來(lái)說(shuō),最重要的編程對(duì)象是DOMDocument。DOMDocument對(duì)象通過(guò)暴露的屬性XMLXML合,可以用數(shù)值訪問(wèn)。、IXMLDOMParseError對(duì)象:用來(lái)驗(yàn)證XML文檔對(duì)于DTD、XSD的正確性。第九章填空題:1、DOMSAX 2、Document 3、startDocument 4、XMLOutPutter 選擇題:1、B 2、A 3、A 4、B 上機(jī)題(1)importjavax.xml.parsers.*;importorg.w3c.dom.*;publicclassdom{publicstaticvoid main(Stringargs[]){try{DocumentBuilderFactory factory DocumentBuilderFactory.newInstance;DocumentBuilderbuilder=factory.newDocumentBuilder;Documentdoc=builder.parse(“order.xml“);NodeListnl=doc.getElementsByTagName(“shipTo“);for(inti=0;i<nl.getLength;i++){Elementnode=(Element)nl.item(i);System.out.print(“name:“);System.out.println(node.getElementsByTagName(“name“).item(0).getFirstChild.getNodeValue);System.out.print(“street:“);System.out.println(node.getElementsByTagName(“street“).item(0).getFirstChild.getNodeValue);System.out.print(“city:“);System.out.println(node.getElementsByTagName(“city“).item(0).getFirstChild.getNodeValue);System.out.print(“state:“);System.out.println(node.getElementsByTagName(“state“).item(0).getFirstChild.getNodeValue);System.out.print(“zip:“);System.out.println(node.getElementsByTagName(“zip“).item(0).getFirstChild.getNodeValue);System.out.println;}NodeListn2=doc.getElementsByTagName(“billTo“);for(inti=0;i<n2.getLength;i++){Elementnode=(Element)n2.item(i);System.out.print(“name:“);System.out.println(node.getElementsByTagName(“name“).item(0).getFirstChild.getNodeValue);System.out.print(“street:“);System.out.println(node.getElementsByTagName(“street“).item(0).getFirstChild.getNodeValue);System.out.print(“city:“);System.out.println(node.getElementsByTagName(“city“).item(0).getFirstChild.getNodeValue);System.out.print(“state:“);System.out.println(node.getElementsByTagName(“state“).item(0).getFirstChild.getNodeValue);System.out.print(“zip:“);System.out.println(node.getElementsByTagName(“zip“).item(0).getFirstChild.getNodeValue);System.out.println;}NodeListn3=doc.getElementsByTagName(“item“);for(inti=0;i<n3.getLength;i++){Elementnode=(Element)n3.item(i);System.out.print(“productName:“);System.out.println(node.getElementsByTagName(“productName“).item(0).getFirstChild.getNodeValue);System.out.print(“quantity:“);System.out.println(node.getElementsByTagName(“quantity“).item(0).getFirstChild.getNodeValue);System.out.print(“USPrice:“);System.out.println(node.getElementsByTagName(“USPrice“).item(0).getFirstChild.getNodeValue);System.out.print(“comment:“);System.out.println(node.getElementsByTagName(“comment“).item(0).getFirstChild.getNodeValue);System.out.println;}}catch(Exceptione){e.printStackTrace;}}}(2)importjavax.xml.parsers.*;importorg.w3c.dom.*;importjava.io.*;importorg.apache.crimson.tree.*;publicclassInsertElement{publicstaticvoid main(Stringargs[]){Elementitems=null;Elementitem=null;ElementproductName=null;Elementquantity=null;ElementUSPrice=null;ElementshipDate=null;try{DocumentBuilderFactory factory DocumentBuilderFactory.newInstance;DocumentBuilderbuilder=factory.newDocumentBuilder;Documentdoc=builder.parse(“order.xml“);NodeListnl=doc.getElementsByTagName(“items“);items=(Element)nl.item(0);item=doc.createElement(“item“);item.setAttribute(“partNum“,“926-AA“);productName=doc.createElement(“productName“);productName.appendChild(doc.createTextNode(“BabyMonitor“));item.appendChild(productName);quantity=doc.createElement(“quantity“);quantity.appendChild(doc.createTextNode(“1“));item.appendChild(quantity);USPrice=doc.createElement(“USPrice“);USPrice.appendChild(doc.createTextNode(“39.98“));item.appendChild(USPrice);shipDate=doc.createElement(“shipDate“);shipDate.appendChild(doc.createTextNode(“1999-05-21“));item.appendChild(shipDate);items.appendChild(item);((XmlDocument)doc).write(newFileOutputStream(“test1.xml“));}catch(Exceptione){e.printStackTrace;}}}2、importjava.io.IOException;importjavax.xml.parsers.*;importorg.xml.sax.Attributes;importorg.xml.sax.SAXException;importorg.xml.sax.helpers.DefaultHandler;publicclassSAXtoMyxml{public static void main(String[] args) ParserConfigurationException,SAXException,IOException{//SAXSAXParserFactorysf=SAXParserFactory.newInstance;SAXParsersax=sf.newSAXParser;//解析器//xmlsax.parse(“order.xml“,newSAXHander);//使用自定義的監(jiān)聽(tīng)器}}//saxclassSAXHanderextendsDefaultHandler{publicvoidstartDocumentthrowsSAXException{System.out.println(“文檔開(kāi)頭“);}publicvoidstartElement(Stringuri,StringlocalName,StringqName,Attributesattributes)throwsSAXException{System.out.println(“元素開(kāi)頭“+qName);}publicvoidcharacters(char[]ch,intstart,intlength)throwsSAXException{Stringtext=newString(ch,start,length);//xmlif(text.trim.equals(““))return;}System.out.println(“文本內(nèi)容“+text);}uri,StringlocalName,StringqName)throwsSAXException{System.out.println(“元素完畢“+qName);}publicvoidendDocumentthrowsSAXException{System.out.println(“文檔完畢“);}}3、importorg.jdom.*;importorg.jdom.output.*;importjava.io.*;publicclassWriteXML{publicvoidBuildXMLthrowsException{Elementroot,student,number,name,age;root=newElement(“student-info“);student=newElement(“student“);number=newElement(“number“);name=newElement(“name“);age=newElement(“age“);Documentdoc=newDocument(root);number.setText(“001“);name.setText(“l(fā)nman“);age.setText(“24“);student.addContent(number);student.addContent(name);student.addContent(age);root.addContent(student);Formatformat=Format.getCompactFormat;format.setEncoding(“gb2312“);format.setIndent(“ “);XMLOutputterXMLOut=newXMLOutputter(format);XMLOut.output(doc,newFileOutputStream(“studentinfo.xml“));}publicstaticvoidmain(String[]args)throwsException{WriteXMLw=newWriteXML;System.out.println(“正在生成XML文檔 “);w.BuildXML;}}第十章填空題:1、流模式 DOM 2、XmlReader 3、XmlDocument 4、WriteXml 選擇題:1、A 2、D 3、A 4、A 上機(jī)題1XMLorder.xml,C:\名目下。、ReadXmlDemo其次步:導(dǎo)入命名空間usingSystem.Xml;第三步:讀取數(shù)據(jù)usingSystem;using System.Xml;namespaceReadXmlDemo2{classClass1{[STAThread]staticvoidMain(string[]args){intws=0;intpi=0;intdc=0;intcc=0;intac=0;intet=0;intel=0;intxd=0;XmlTextReader textReader = new order.xml“);while (textReader.Read){XmlNodeType nType = if (nType == {Console.WriteLine(“Declaration:“ textReader.Name.ToString);xd = xd + 1;}if( nType == XmlNodeTypement){Console.WriteLine(“Comment:“ textReader.Name.ToString);cc = cc + 1;}if( nType == XmlNodeType.Attribute){Console.WriteLine(“Attribute:“ textReader.Name.ToString);ac = ac + 1;}if ( nType == XmlNodeType.Element){Console.WriteLine(“Element:“ textReader.Name.ToString);el = el + 1;}if ( nType == XmlNodeType.Entity ){Console.WriteLine(“Entity:“ textReader.Name.ToString);et = et + 1;}if( nType == XmlNodeType.ProcessingInstruction){Console.WriteLine(“Process Instruction:“ textReader.Name.ToString);pi = pi + 1;}if( nType == XmlNodeType.DocumentType){Console.WriteLine(“DocumentType:“ textReader.Name.ToString);dc = dc + 1;}if ( nType == XmlNodeType.Whitespace ){Console.WriteLine(“WhiteSpace:“ textReader.Name.ToString);ws = ws + 1;}}Console.WriteLine(“Total Comments:“ + cc.ToString);Console.WriteLine(“Total Attributes:“ ac.ToString);Console.WriteLine(“TotalElements:“+ el.ToString);Console.WriteLine(“TotalEntity:“+et.ToString);Console.WriteLine(“TotalProcessInstructions:“ +pi.ToString);Console.WriteLine(“Total Declaration:“ xd.ToString);Console.WriteLine(“Total DocumentType:“ dc.ToString);Console.WriteLine(“Total WhiteSpaces:“ +ws.ToString);}}}、首先將要用到的文件order.xmlbin\Debug接著聲明窗體級(jí)的數(shù)據(jù)集對(duì)象,代碼如下:DataSetds=newDataSet;然后,編寫(xiě)各控件相關(guān)的大事觸發(fā)程序代碼:顯示“讀取xml文檔”的按鈕的單擊大事觸發(fā)程序代碼如下:privatevoidbtnReadXML_Click(objectsender,System.EventArgse){ds.ReadXml(“order.xml“);dataGrid1.DataSource=ds.Tables[0];}顯示“將數(shù)據(jù)集中的架構(gòu)寫(xiě)入文件”的按鈕的單擊大事觸發(fā)程序代碼如下:private void btnWriteXmlSchema_Click(object System.EventArgse){ds.WriteXmlSchema(“order.xsd“);}2XMLbook.xmlNavigateXmlDocWINDOWS程序;10-33usingSystem.Xml;usingSystem.IO;usingSystem;usingSystem.Drawing;usingSystem.Collections;usingSystemponentModel;usingSystem.Windows.Forms;usingSystem.Data;usingSystem.Xml;usingSystem.IO;namespaceNavigateXmlDoc{///<summary>///SummarydescriptionforForm1.///</summary>publicclassForm1:System.Windows.Forms.Form{privateSystem.Windows.Forms.GroupBoxgroupBox4;privateSystem.Windows.Forms.Buttonbtn_FindNode;privateSystem.Windows.Forms.TextBoxtxtElementValue;privateSystem.Windows.Forms.GroupBoxgroupBox5;privateSystem.Windows.Forms.ButtonbtnDocElement;privateSystem.Windows.Forms.ButtonbtnFirstChild;privateSystem.Windows.Forms.ButtonbtnLastChild;privateSystem.Windows.Forms.ButtonbtnNextSib;privateSystem.Windows.Forms.ButtonbtnParentNode;privateSystem.Windows.Forms.ButtonbtnPrevSib;privateSystem.Windows.Forms.GroupBoxgroupBox2;privateSystem.Windows.Forms.TextBoxtxtResults;privateSystem.Windows.Forms.ButtonbtnClose;privateSystem.Windows.Forms.GroupBoxgroupBox1;privateSystem.Windows.Forms.ButtonbtnMinus;privateSystem.Windows.Forms.ButtonbtnPlus;privateSystem.Windows.Forms.ButtonbtnLoad;privateSystem.Windows.Forms.TextBoxtxtDocument;privateSystem.Windows.Forms.GroupBoxgroupBox3;privateSystem.Windows.Forms.ButtonbtnGetByName;privateSystem.Windows.Forms.TextBoxtxtElement;///<summary>///Requireddesignervariable.///</summary>privateSystemponentModel.Containercomponents=null;privateXmlDocumentdoc;privateXmlNodecurrentNode;publicForm1{call
////RequiredforWindowsFormDesignersupport//InitializeComponent;////TODO:AddanyconstructorcodeafterInitializeComponent//}///<summary>///Cleanupanyresourcesbeingused.///</summary>protectedoverridevoidDispose(booldisposing){if(disposing){if(components!=null){components.Dispose;}}base.Dispose(disposing);}//此處省略的為窗體設(shè)計(jì)器自動(dòng)生成的代碼///<summary>///Themainentrypointfortheapplication.///</summary>[STAThread]staticvoidMain{Application.Run(newForm1);}privatevoidbtnPlus_Click(objectsender,System.EventArgse){if(txtDocument.Font.SizeInPoints<32){txtDocument.Font=newFont(“MicrosoftSansSerif“,txtDocument.Font.Size+2);}}privatevoidbtnMinus_Click(objectsender,System.EventArgse){if(txtDocument.Font.SizeInPoints>8){txtDocument.Font=newFont(“MicrosoftSansSerif“,txtDocument.Font.Size-2);}}privatevoidbtnLoad_Click(objectsender,System.EventArgse){StringfileName=@“..\..\book.xml“;StreamReaderreader=newStreamReader(fileName);txtDocument.Text=reader.ReadToEnd;doc=newXmlDocument;doc.PreserveWhitespace=false;doc.LoadXml(txtDocument.Text);}privatevoidbtnDocElement_Click(objectsender,System.EventArgse){XmlNodelastNode;lastNode=currentNode;try{currentNode=doc.DocumentElement;txtResults.Text=currentNode.OuterXml;}catch(Exceptione1){出錯(cuò)“,}
MessageBox.Show(“沒(méi)有匹配的節(jié)點(diǎn)“+e1.ToString,“導(dǎo)航MessageBoxButtons.OK,MessageBoxIcon.Asterisk);currentNode=lastNode;}privatevoidbtnFirstChild_Click(objectsender,System.EventArgse){XmlNodelastNode;lastNode=currentNode;try{currentNode=currentNode.FirstChild;txtResults.Text=currentNode.OuterXml;}catch(Exceptione1)出錯(cuò)“,
{MessageBox.Show(“沒(méi)有匹配的節(jié)點(diǎn)“+e1.ToString,“導(dǎo)航MessageBoxButtons.OK,MessageBoxIcon.Asterisk);currentNode=lastNode;}}privatevoidbtnLastChild_Click(objectsender,System.EventArgse){XmlNodelastNode;lastNode=currentNode;try{currentNode=currentNode.LastChild;txtResults.Text=currentNode.OuterXml;}catch(Exceptione1){出錯(cuò)“,}
MessageBox.Show(“沒(méi)有匹配的節(jié)點(diǎn)“+e1.ToString,“導(dǎo)航MessageBoxButtons.OK,MessageBoxIcon.Asterisk);currentNode=lastNode;}privatevoidbtnNextSib_Click(objectsender,System.EventArgse){XmlNodelastNode;lastNode=currentNode;try{currentNode=currentNode.NextSibling;txtResults.Text=currentNode.OuterXml;}catch(Exceptione1){出錯(cuò)“,
MessageBox.Showe1.ToString,MessageBoxButtons.OK,MessageBoxIcon.Asterisk);currentNode=lastNode;}}privatevoidbtnParentNode_Click(objectsender,System.EventArgse){XmlNodelastNode;lastNode=currentNode;try{currentNode=currentNode.ParentNode;txtResults.Text=currentNode.OuterXml;}catch(Exceptione1){錯(cuò)“,
MessageBox.Show(e1.ToString,MessageBoxButtons.OK,MessageBoxIcon.Asterisk);currentNode=lastNode;}}privatevoidbtnPrevSib_Click(objectsender,System.EventArgse){XmlNodelastNode;lastNode=currentNode;try{currentNode=currentNode.PreviousSibling;txtResults.Text=currentNode.OuterXml;}catch(Exceptione1){出錯(cuò)“,}
MessageBox.Show(“沒(méi)有匹配的節(jié)點(diǎn)“+e1.ToString,“導(dǎo)航MessageBoxButtons.OK,MessageBoxIcon.Asterisk);currentNode=lastNode;}privatevoidbtnGetByName_Click(objectsender,System.EventArgse){txtResults.Clear;stringstrNodes=““;try{XmlNodeList elemList =doc.GetElementsByTagName(txtElement.Text);for(inti=0;i<elemList.Count;i++){strNodes=strNodes+““+(elemList[i].InnerXml);}txtResults.Text=strNodes;}catch(Exceptione1){出錯(cuò)“,
MessageBox.Showe1.ToString,MessageBoxButtons.OK,MessageBoxIcon.Asterisk);}}privatevoidbtn_FindNode_Click(objectsender,System.EventArgse){txtResults.Clear;stringstrElementValue=txtElementValue.Text;try{XmlNodebook;XmlNoderoot=doc.DocumentElement;book=root.S
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度雛雞養(yǎng)殖與農(nóng)業(yè)觀光旅游合作開(kāi)發(fā)合同4篇
- 2025版影視廣告拍攝攝影棚租賃專項(xiàng)合同3篇
- 二零二五年度船舶醫(yī)療救護(hù)船員勞動(dòng)合同3篇
- 2025年度家庭園藝設(shè)計(jì)與養(yǎng)護(hù)服務(wù)合同規(guī)范4篇
- 二零二四年度校園團(tuán)體課外活動(dòng)合作協(xié)議3篇
- 2025年程力品牌危險(xiǎn)品廂式車廠家智能化升級(jí)改造合同2篇
- 2025版?zhèn)€人債權(quán)轉(zhuǎn)讓合同范本詳解與下載3篇
- 二零二五年度智能交通管理系統(tǒng)采購(gòu)合同標(biāo)的創(chuàng)新版3篇
- 二零二五年度健康食品產(chǎn)品認(rèn)證及功效驗(yàn)證合同4篇
- 2025年度電動(dòng)汽車充電樁研發(fā)與生產(chǎn)技術(shù)許可合同4篇
- 焊接機(jī)器人在汽車制造中應(yīng)用案例分析報(bào)告
- 合成生物學(xué)在生物技術(shù)中的應(yīng)用
- 中醫(yī)門(mén)診病歷
- 廣西華銀鋁業(yè)財(cái)務(wù)分析報(bào)告
- 無(wú)違法犯罪記錄證明申請(qǐng)表(個(gè)人)
- 電捕焦油器火災(zāi)爆炸事故分析
- 大學(xué)生勞動(dòng)教育PPT完整全套教學(xué)課件
- 繼電保護(hù)原理應(yīng)用及配置課件
- 《殺死一只知更鳥(niǎo)》讀書(shū)分享PPT
- 蓋洛普Q12解讀和實(shí)施完整版
- 2023年Web前端技術(shù)試題
評(píng)論
0/150
提交評(píng)論