xml介绍系列(6)

  • 作者:未知 来源:未知 添加时间:2006年7月3日 字体:

  • 系列之十二:格式化xml(一)

    使用&#106avascript格式化xml文档
    你如果要想把xml文档中的数据显示在html页面中,
    你可以使用&#106avascript来导入数据,
    你要想看到xml和html之间是如何互补的话,可以
    比较这个xml文档(note.xml)和这个html文档(note.htm使用了&#106avascript
    从xml中读出数据然后显示在html中)
    文件代码如下:
    note.xml
    <@xml version="1.0"@>
    <note>
    <to>tove</to>
    <from>jani</from>
    <heading>reminder</heading>
    <body>don't forget me this weekend!</body>
    </note>

    note.htm
    <html>
    <head>

    <script language="&#106avascript" for="window" event="onload">
    var xmldoc = new activexobject("microsoft.xmldom");
    xmldoc.async="false";
    xmldoc.load("note.xml");
    nodes = xmldoc.documentelement.childnodes;
    to.innertext = nodes.item(0).text;
    from.innertext = nodes.item(1).text;
    header.innertext = nodes.item(2).text;
    body.innertext = nodes.item(3).text;
    </script>

    <title>html using xml data</title>
    </head>

    <body bgcolor="yellow">

    <h1>refsnes data internal note</h1>

    <b>to: </b>
    <span id="to"> </span>



    <b>from: </b>
    <span id="from"></span>
    <hr>

    <b><span id="header"></span></b>

    <hr>
    <span id="body"></span>

    </body>
    </html>

    翻译:batman
    系列之十三:格式化xml(二)
    使用css格式化xml
    下面来示范如何使用css文件来格式化xml文件
    shakespeare.xml
    <@xml version="1.0"@>
    <@xml-stylesheet type="text/css" href="/1fanwencom/shakespeare.css"@>
    <shakespeare-index>
    <play>
    <title>all's well that ends well</title>
    <path>all_well.xml</path>
    <personae>
    <title>dramatis personae</title>
    <persona>king of france</persona>
    <persona>duke of florence</persona>
    <persona>bertram, count of rousillon.</persona>
    <persona>lafeu, an old lord.</persona>
    <persona>parolles, a follower of bertram.</persona>
    <pgroup>
    <persona>steward</persona>
    <persona>clown</persona>
    <grpdescr>servants to the countess of rousillon.</grpdescr>
    </pgroup>
    <persona>a page. </persona>
    <persona>countess of rousillon, mother to bertram. </persona>
    <persona>helena, a gentlewoman protected by the countess.</persona>
    <persona>an old widow of florence. </persona>
    <persona>diana, daughter to the widow.</persona>
    <pgroup>
    <persona>violenta</persona>
    <persona>mariana</persona>
    <grpdescr>neighbours and friends to the widow.</grpdescr>
    </pgroup>
    <persona>lords, officers, soldiers, !amp;amp;c., french and florentine.</persona>
    </personae>
    </play>

    <play>
    <title>as you like it</title>
    <path>as_you.xml</path>
    <personae>
    <title>dramatis personae</title>

    <persona>duke senior, living in banishment.</persona>
    <persona>duke frederick, his brother, an usurper of his dominions.</persona>

    <pgroup>
    <persona>amiens</persona>
    <persona>jaques</persona>
    <grpdescr>lords attending on the banished duke.</grpdescr>
    </pgroup>

    <persona>le beau, a courtier attending upon frederick.</persona>
    <persona>charles, wrestler to frederick.</persona>

    <pgroup>
    <persona>oliver</persona>
    <persona>jaques </persona>
    <persona>orlando</persona>
    <grpdescr>sons of sir rowland de boys.</grpdescr>
    </pgroup>


    <pgroup>
    <persona>adam</persona>
    <persona>dennis</persona>
    <grpdescr>servants to oliver.</grpdescr>
    </pgroup>

    <persona>touchstone, a clown.</persona>
    <persona>sir oliver martext, a vicar.</persona>

    <pgroup>
    <persona>corin</persona>
    <persona>silvius</persona>
    <grpdescr>shepherds.</grpdescr>
    </pgroup>

    <persona>william, a country fellow in love with audrey.</persona>
    <persona>a person representing hymen. </persona>
    <persona>rosalind, daughter to the banished duke.</persona>
    <persona>celia, daughter to frederick.</persona>
    <persona>phebe, a shepherdess.</persona>
    <persona>audrey, a country wench.</persona>
    <persona>lords, pages, and attendants, !amp;amp;c.</persona>
    </personae>

    </play>

    <play>
    <title>a midsummer night's dream</title>
    <path>dream.xml</path>
    <personae>
    <title>dramatis personae</title>

    <persona>theseus, duke of athens.</persona>
    <persona>egeus, father to hermia.</persona>

    <pgroup>
    <persona>lysander</persona>
    <persona>demetrius</persona>
    <grpdescr>in love with hermia.</grpdescr>
    </pgroup>

    <persona>philostrate, master of the revels to theseus.</persona>
    <persona>quince, a carpenter.</persona>
    <persona>snug, a joiner.</persona>
    <persona>bottom, a weaver.</persona>
    <persona>flute, a bellows-mender.</persona>
    <persona>snout, a tinker.</persona>
    <persona>starveling, a tailor.</persona>
    <persona>hippolyta, queen of the amazons, betrothed to theseus.</persona>
    <persona>hermia, daughter to egeus, in love with lysander.</persona>
    <persona>helena, in love with demetrius.</persona>
    <persona>oberon, king of the fairies.</persona>
    <persona>titania, queen of the fairies.</persona>
    <persona>puck, or robin goodfellow.</persona>

    <pgroup>
    <persona>peaseblossom</persona>
    <persona>cobweb</persona>
    <persona>moth</persona>
    <persona>mustardseed</persona>
    <grpdescr>fairies.</grpdescr>
    </pgroup>

    <persona>other fairies attending their king and queen.</persona>
    <persona>attendants on theseus and hippolyta.</persona>
    </personae>
    </play>

    <play>
    <title>the tragedy of hamlet, prince of denmark</title>
    <path>hamlet.xml</path>
    <personae>
    <title>dramatis personae</title>

    <persona>claudius, king of denmark. </persona>
    <persona>hamlet, son to the late, and nephew to the present king.</persona>
    <persona>polonius, lord chamberlain. </persona>
    <persona>horatio, friend to hamlet.</persona>
    <persona>laertes, son to polonius.</persona>
    <persona>lucianus, nephew to the king.</persona>

    <pgroup>
    <persona>voltimand</persona>
    <persona>cornelius</persona>
    <persona>rosencrantz</persona>
    <persona>guildenstern</persona>
    <persona>osric</persona>
    <grpdescr>courtiers.</grpdescr>
    </pgroup>

    <persona>a gentleman</persona>
    <persona>a priest. </persona>

    <pgroup>
    <persona>marcellus</persona>
    <persona>bernardo</persona>
    <grpdescr>officers.</grpdescr>
    </pgroup>

    <persona>francisco, a soldier.</persona>
    <persona>reynaldo, servant to polonius.</persona>
    <persona>players.</persona>
    <persona>two clowns, grave-diggers.</persona>
    <persona>fortinbras, prince of norway. </persona>
    <persona>a captain.</persona>
    <persona>english ambassadors. </persona>
    <persona>gertrude, queen of denmark, and mother to hamlet. </persona>
    <persona>ophelia, daughter to polonius.</persona>
    <persona>lords, ladies, officers, soldiers, sailors, messengers, and other attendants.</persona>
    <persona>ghost of hamlet's father. </persona>
    </personae>

    </play>

    <play>
    <title>the life of henry the fifth</title>
    <path>hen_v.xml</path>
    <personae>
    <title>dramatis personae</title>

    <persona>king henry, the fifth. </persona>

    <pgroup>
    <persona>duke of gloucester</persona>
    <persona>duke of bedford</persona>
    <grpdescr>brothers to the king.</grpdescr>
    </pgroup>

    <persona>duke of exeter, uncle to the king. </persona>
    <persona>duke of york, cousin to the king. </persona>
    <persona>earl of salisbury</persona>
    <persona>earl of westmoreland</persona>
    <persona>earl of warwick</persona>
    <persona>bishop of canterbury</persona>
    <persona>bishop of ely</persona>
    <persona>earl of cambridge</persona>
    <persona>lord scroop</persona>
    <persona>sir thomas grey</persona>

    <pgroup>
    <persona>sir thomas erpingham</persona>
    <persona>gower</persona>
    <persona>fluellen</persona>
    <persona>macmorris</persona>
    <persona>jamy</persona>
    <grpdescr>officers in king henry's army.</grpdescr>
    </pgroup>


    <pgroup>
    <persona>bates</persona>
    <persona>court</persona>
    <persona>williams</persona>
    <grpdescr>soldiers in the same.</grpdescr>
    </pgroup>

    <persona>pistol</persona>
    <persona>nym</persona>
    <persona>bardolph</persona>
    <persona>boy</persona>
    <persona>a herald.</persona>
    <persona>charles the sixth, king of france. </persona>
    <persona>lewis, the dauphin. </persona>
    <persona>duke of burgundy</persona>
    <persona>duke of orleans</persona>
    <persona>duke of bourbon</persona>
    <persona>the constable of france. </persona>

    <pgroup>
    <persona>rambures</persona>
    <persona>grandpre</persona>
    <grpdescr>french lords.</grpdescr>
    </pgroup>

    <persona>governor, of harfleur.</persona>
    <persona>montjoy, a french herald.</persona>
    <persona>ambassadors to the king of england.</persona>
    <persona>isabel, queen of france. </persona>
    <persona>katharine, daughter to charles and isabel.</persona>
    <persona>alice, a lady attending on her.</persona>
    <persona>hostess of a tavern in eastcheap formerly mistress quickly, and now married to pistol.</persona>
    <persona>lords, ladies, officers, soldiers, citizens, messengers, and attendants. chorus.</persona>
    </personae>

    </play>

    <play>
    <title>the tragedy of king lear</title>
    <path>lear.xml</path>

    <personae>
    <title>dramatis personae</title>

    <persona>lear, king of britain </persona>
    <persona>king of france</persona>
    <persona>duke of burgundy</persona>
    <persona>duke of cornwall</persona>
    <persona>duke of albany</persona>
    <persona>earl of kent</persona>
    <persona>earl of gloucester</persona>
    <persona>edgar, son to gloucester.</persona>
    <persona>edmund, bastard son to gloucester.</persona>
    <persona>curan, a courtier.</persona>
    <persona>old man, tenant to gloucester.</persona>
    <persona>doctor</persona>
    <persona>fool</persona>
    <persona>oswald, steward to goneril.</persona>
    <persona>a captain employed by edmund. </persona>
    <persona>gentleman attendant on cordelia. </persona>
    <persona>a herald.</persona>
    <persona>servants to cornwall.</persona>

    <pgroup>
    <persona>goneril</persona>
    <persona>regan</persona>
    <persona>cordelia</persona>
    <grpdescr>daughters to lear.</grpdescr>
    </pgroup>

    <persona>knights of lear's train, captains, messengers, soldiers, and attendants</persona>
    </personae>

    </play>

    <play>
    <title>the tragedy of macbeth</title>
    <path>macbeth.xml</path>

    <personae>
    <title>dramatis personae</title>

    <persona>duncan, king of scotland.</persona>

    <pgroup>
    <persona>malcolm</persona>
    <persona>donalbain</persona>
    <grpdescr>his sons.</grpdescr>
    </pgroup>


    <pgroup>
    <persona>macbeth</persona>
    <persona>banquo</persona>
    <grpdescr>generals of the king's army.</grpdescr>
    </pgroup>


    <pgroup>
    <persona>macduff</persona>
    <persona>lennox</persona>
    <persona>ross</persona>
    <persona>menteith</persona>
    <persona>angus</persona>
    <persona>caithness</persona>
    <grpdescr>noblemen of scotland.</grpdescr>
    </pgroup>

    <persona>fleance, son to banquo.</persona>
    <persona>siward, earl of northumberland, general of the english forces.</persona>
    <persona>young siward, his son.</persona>
    <persona>seyton, an officer attending on macbeth.</persona>
    <persona>boy, son to macduff. </persona>
    <persona>an english doctor. </persona>
    <persona>a scotch doctor. </persona>
    <persona>a soldier.</persona>
    <persona>a porter.</persona>
    <persona>an old man.</persona>
    <persona>lady macbeth</persona>
    <persona>lady macduff</persona>
    <persona>gentlewoman attending on lady macbeth. </persona>
    <persona>hecate</persona>
    <persona>three witches.</persona>
    <persona>apparitions.</persona>
    <persona>lords, gentlemen, officers, soldiers, murderers, attendants, and messengers. </persona>
    </personae>

    </play>

    <play>
    <title>the tragedy of richard the third</title>
    <path>rich_iii.xml</path>

    <personae>
    <title>dramatis personae</title>

    <persona>king edward the fourth</persona>

    <pgroup>
    <persona>edward, prince of wales, afterwards king edward v.</persona>
    <persona>richard, duke of york </persona>
    <grpdescr>sons to the king.</grpdescr>
    </pgroup>


    <pgroup>
    <persona>george, duke of clarence</persona>
    <persona>richard, duke of gloucester, afterwards king richard iii.</persona>
    <grpdescr>brothers to the king.</grpdescr>
    </pgroup>

    <persona>a young son of clarence. </persona>
    <persona>henry, earl of richmond, afterwards king henry vii.</persona>
    <persona>cardinal bourchier, archbishop of canterbury. </persona>
    <persona>thomas rotherham, archbishop of york. </persona>
    <persona>john morton, bishop of ely. </persona>
    <persona>duke of buckingham</persona>
    <persona>duke of norfolk</persona>
    <persona>earl of surrey, his son. </persona>
    <persona>earl rivers, brother to elizabeth. </persona>

    <pgroup>
    <persona>marquis of dorset</persona>
    <persona>lord grey</persona>
    <grpdescr>sons to elizabeth.</grpdescr>
    </pgroup>

    <persona>earl of oxford</persona>
    <persona>lord hastings</persona>
    <persona>lord stanley, called also earl of derby. </persona>
    <persona>lord lovel</persona>
    <persona>sir thomas vaughan</persona>
    <persona>sir richard ratcliff</persona>
    <persona>sir william catesby</persona>
    <persona>sir james tyrrel</persona>
    <persona>sir james blount</persona>
    <persona>sir walter herbert</persona>
    <persona>sir robert brakenbury, lieutenant of the tower. </persona>
    <persona>christopher urswick, a priest. </persona>
    <persona>another priest. </persona>

    <pgroup>
    <persona>tressel</persona>
    <persona>berkeley</persona>
    <grpdescr>gentlemen attending on the lady anne.</grpdescr>
    </pgroup>

    <persona>lord mayor of london. </persona>
    <persona>sheriff of wiltshire. </persona>
    <persona>elizabeth, queen to king edward iv. </persona>
    <persona>margaret, widow of king henry vi. </persona>
    <persona>duchess of york, mother to king edward iv.</persona>
    <persona>lady anne, widow of edward prince of wales, son to king henry vi; afterwards married to richard.</persona>
    <persona>a young daughter of clarence [margaret plantagenet] </persona>
    <persona>ghosts of those murdered by richard iii., lords and other attendants; a pursuivant scrivener, citizens, murderers, messengers soldiers, !amp;amp;c.</persona>
    </personae>

    </play>

    <play>
    <title>the tempest</title>
    <path>tempest.xml</path>

    <personae>
    <title>dramatis personae</title>

    <persona>alonso, king of naples.</persona>
    <persona>sebastian, his brother.</persona>
    <persona>prospero, the right duke of milan.</persona>
    <persona>antonio, his brother, the usurping duke of milan.</persona>
    <persona>ferdinand, son to the king of naples.</persona>
    <persona>gonzalo, an honest old counsellor.</persona>

    <pgroup>
    <persona>adrian</persona>
    <persona>francisco</persona>
    <grpdescr>lords.</grpdescr>
    </pgroup>

    <persona>caliban, a savage and deformed slave.</persona>
    <persona>trinculo, a jester.</persona>
    <persona>stephano, a drunken butler.</persona>
    <persona>master of a ship. </persona>
    <persona>boatswain. </persona>
    <persona>mariners. </persona>
    <persona>miranda, daughter to prospero.</persona>
    <persona>ariel, an airy spirit.</persona>

    <pgroup>
    <persona>iris</persona>
    <persona>ceres</persona>
    <persona>juno</persona>
    <persona>nymphs</persona>
    <persona>reapers</persona>
    <grpdescr>presented by spirits.</grpdescr>
    </pgroup>

    <persona>other spirits attending on prospero.</persona>
    </personae>


    </play>
    </shakespeare-index>

    格式化用的css文件如下:shakespeare.css
    play
    {
    background-color: white;
    width: 100%
    }
    title
    {
    color: #000088;
    display: block;
    font-size: 24pt;
    margin-bottom: 12pt;
    margin-left: 24pt;
    margin-top: 12pt
    }
    fm
    {
    display: block;
    font-size: 10pt;
    margin-bottom: 18pt;
    margin-top: 18pt
    }
    p
    {
    display: block
    }
    personae
    {
    }
    pgroup
    {
    display: block;
    margin-bottom: 18pt;
    margin-top: 18pt
    }
    persona
    {
    color: #000022;
    display: block;
    font-size: 14pt;
    margin-left: 5pt
    }
    grpdescr
    {
    color: #440000;
    display: block;
    font-size: 14pt;
    margin-left: 24pt
    }
    scndescr
    {
    color: #004400;
    display: block;
    font-size: 14pt;
    margin-bottom: 12pt;
    margin-left: 12pt;
    margin-top: 6pt
    }
    playsubt
    {
    color: #880000;
    display: block;
    font-size: 36pt;
    margin-bottom: 18pt;
    margin-top: 36pt;
    text-align: center
    }
    induct
    {
    display: block;
    font-style: italic
    }
    act
    {
    }
    scene
    {
    }
    prologue
    {
    display: block;
    font-style: italic
    }
    epilogue
    {
    display: block;
    font-style: italic
    }
    speech
    {
    display: block
    }
    speaker
    {
    color: #880000;
    display: block;
    font-size: 14pt;
    margin-left: 12pt;
    margin-top: 12pt
    }
    line
    {
    display: block;
    font-size: 12pt;
    margin-left: 24pt
    }
    stagedir
    {
    color: #004400;
    display: block;
    font-size: 14pt;
    margin-bottom: 12pt;
    margin-left: 12pt;
    margin-top: 6pt
    }
    subtitle
    {
    }
    subhead
    {
    }
    path
    {
    color: green;
    display: block;
    font-size: 14pt;
    font-style: italic;
    margin-left: 12pt
    }

    看上去好象使用css来显示xml很不错的,但是将来肯定是要使用xsl来显示xml文件的。

  • 上一篇:xml介绍系列(7)
  • 下一篇:xml介绍系列(5)
  • 最后更新时间:2024年12月22日
  • 返回页面顶端
ppdesk