资源预览内容
第1页 / 共246页
第2页 / 共246页
第3页 / 共246页
第4页 / 共246页
第5页 / 共246页
第6页 / 共246页
第7页 / 共246页
第8页 / 共246页
第9页 / 共246页
第10页 / 共246页
亲,该文档总共246页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
1 XML StevenHolzner SamsTeachYourselfXMLin21Days ThirdEdition 2003 2 1 XML基础 3 MarkupLanguages HelloFromHTMLAnHTMLDocumentThisisanHTMLdocument 标记是文档中数据的描述和解释 4 XML eXtensibleMarkupLanguage元语言 创建标记语言的语言 5 ElementsarenestedRootelementcontainsallothers Element ortag names Example elements Rootelement Emptyelement attributes declaration 6 MoreTerminology Johnisanicefellow21MainSt Openingtag Closingtag Whatisopenmustbeclosed Nestedelement childofPerson ParentofAddress Ancestorofnumber standalone text notusefulasdata ChildofAddress DescendantofPerson ContentofPerson 7 IE中浏览XML文档 8 AnXMLDocumentUsingaStyleSheet Johnisanicefellow21MainSt 9 ch01 04 css Person display block font size 18pt color 0000ff text align left 10 使用JavaScript抽取数据 HelloFromXMLThisisanXMLdocument 11 使用JavaScript抽取数据 RetrievingdatafromanXMLdocumentfunctiongetData xmldoc document all firstXML XMLDocument nodeDoc xmldoc documentElement nodeHeading nodeDoc firstChild outputMessage Heading nodeHeading firstChild nodeValue message innerHTML outputMessage 12 使用JavaScript抽取数据 RetrievingdatafromanXMLdocument 13 使用JavaScript抽取数据 14 使用Java从XML文档中抽取数据 importjavax xml parsers importorg w3c dom importjava io publicclassch01 06 staticpublicvoidmain String argv try DocumentBuilderFactorydbf DocumentBuilderFactory newInstance DocumentBuilderdb null try db dbf newDocumentBuilder catch ParserConfigurationExceptionpce Documentdoc null doc db parse ch01 02 xml 15 使用Java从XML文档中抽取数据 for Nodenode doc getDocumentElement getFirstChild node null node node getNextSibling if nodeinstanceofElement if node getNodeName equals heading StringBufferbuffer newStringBuffer for Nodesubnode node getFirstChild subnode null subnode subnode getNextSibling if subnodeinstanceofText buffer append subnode getNodeValue System out println buffer toString catch Exceptione e printStackTrace 16 使用Java从XML文档中抽取数据 javach01 06HelloFromXML 17 Well formedXMLDocuments MusthavearootelementEveryopeningtagmusthavematchingclosingtagElementsmustbeproperlynestedisano noAnattributenamecanoccuratmostonceinanopeningtag Ititoccurs Itmusthaveavalue booleanattrs likeinHTML arenotallowed Thevaluemustbequoted with or XMLprocessorsarenotsupposedtotryandfixill formeddocuments unlikeHTMLbrowsers 18 ValidXMLDocuments HelloFromXMLThisisanXMLdocument 19 ValidXMLDocument AvalidXMLdocumentisdefinedbytheW3Casawell formedXMLdocumentwhichalsoconformstotherulesofaDocumentTypeDefinition DTD oranXMLSchema ski m XSD 20 XML应用 XML用于存储 传输 结构化数据纯文本格式使它容易被在互联网上传输并被不同平台上的应用所处理过去5年中 已经出现了上百种XML子语言 21 使用MathML显示4x2 5x 6 0 4x 6 0 22 在Amaya浏览器中显示MathML文档 23 XHTML ExtensibleHypertextMarkupLanguage更加严格允许增加自己的标记HTML4 01 当前版本 24 AnXHTMLDocument AnXHTMLPageWelcometoXHTML ThisisanXHTMLdocument Prettycool eh 25 在IE中显示 26 AnSVGDocument SVGExample 27 练习 validXML文档一定是well formed吗 well formedXML文档一定是valid吗 28 编辑XML文档 XML编辑器XMLSpyVisualStudioXMLDesignerXRayXML浏览器IE MostpowerfulgeneralJumbo CMLbrowser 29 Jumbo 30 XMLValidators MakesureitiswellformedandvalidScholarlyTechnologyGroup svalidatorMicrosoft sVisualStudio NET 31 error xml HelloFromXMLThisisanXMLdocument 32 33 XMLvalidationinVisualStudio NET 34 建立一个完整的XML文档 HelloFromXMLThisisanXMLdocument 35 XML文档 PrologsXMLdeclarationsProcessinginstructionsElementsandattributesCommentsCDATAsectionsEntities 36 字符编码问题 ASCII仅有256个字符Chinese Armenian Hebrew Thai Tibetan从数量上 通用上 ASCII不能在Web上使用Unicode http www unicode org 65 536个字符前256个对应ASCII但让所有的软件转去支持Unicode太困难UCSTransformationFormat 8 UTF 8 37 UTF 8 所有ASCII字符的编码保持不变 8bit 其它Unicode字符使用2字节 直至6字节编码W3CrequiresallXMLprocessorstosupportbothUTF 8 UTF 16大部分支持UTF 8 38 字符实体引用 HelloFromXMLThistextisinsideaelement 39 字符实体引用 40 字符实体引用 Replacedwith 41 实体 实体是一大段文本的别名假如你为你的信件署名定义了一个实体lettersign 它代表下面这一大段文本 张三某网络公司销售部门北京市海淀区中关村88号 100000 42 实体 邮件 收件人 李四 收件人 主题 hello 主题 正文 晚上吃饭 lettersign 正文 邮件 43 一般实体和参数实体 一般实体声明 ENTITYlettersign 张三某网络公司销售部门北京市海淀区中关村88号 100000 参数实体声明 ENTITY 实体名 文本内容 44 实体引用 的用法都会引起错误 尽管在一个实体中可以再引用其它实体 但是不能出现循环引用 也就是说 一个实体不能引用它自己 同样 也不能出现实体A引用实体B 然后实体B再反过来引用实体A的情况 实体引用不能在DOCTYPE声明中出现 实体引用的文本必须是形式良好的XML 45 张三 A公司 李四B公司 B公司地址 地址 王五 B公司 B公司地址 地址 一旦哪个公司搬家了 只须改变实体声明中有关该公司的地址 所有这个公司的联系人的地址也就都改过来了 46 空白 Spaces carriagereturns linefeeds andtabsarealltreatedaswhitespace HelloFromXMLThisisanXMLdocument heading HelloFromXMLThisisanXMLdocument 47 Prologs 序言 XMLdeclarationsXMLcommentsprocessinginstructionswhitespacedoctypedeclarations 48 KellyGraceOctober15 2005Printer XMLDeclaration XMLComments ProcessingInstruction由处理器定义 RootElement Element 属性 49 CDATA CDATAstandsforcharacterdata PCDATAstandsforparsedcharacterdata 50 Here showtheelementstarts KellyGraceOctober15 2005Printer111 111 00 51 InternetExplorertreatsthisCDATAsectionasunparsedtext 52 练习 一个文本编辑器保存XML文档时 并不提示字符集 该编辑器是否可用 把文本数据 Thisisaelement 包含在元素中 怎样做才不会迷惑XMLprocessor XMLprolog可以包含哪些项目 53 XMLNamespaces 解决文档内和文档间名字冲突的机制NamespacedeclarationNamespace 符号串 通常为URLPrefix 名字空间的缩写 相当于别名Actualname elementorattribute prefix nameDeclarations prefixes作用范围 scope 与begin end类似Example backpackcyberpet Defaultnamespace toynamespace re
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号