栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

用HTML内联外部CSS

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用HTML内联外部CSS

您可以尝试CSSBox。只需查看软件包中包含的 ComputeStyles
演示(有关运行该演示的信息,请参阅分发软件包中的 doc / examples / README
文件)。它计算所有样式,并使用相应的内联样式定义创建一个新的HTML文档(以DOM表示)。

来源在 src / org / fit / cssbox / demo / ComputeStyles.java中
,非常简短。实际上,它使用jStyleParser来完成主要工作,CSSBox为此提供了一个更好的接口。

        //Open the network connection         documentSource docSource = new DefaultdocumentSource(args[0]);        //Parse the input document        DOMSource parser = new DefaultDOMSource(docSource);        document doc = parser.parse();        //Create the CSS analyzer        DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());        da.attributesToStyles(); //convert the HTML presentation attributes to inline styles        da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet        da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet        da.getStyleSheets(); //load the author style sheets        //Compute the styles        System.err.println("Computing style...");        da.stylesToDomInherited();        //Save the output        PrintStream os = new PrintStream(new FileOutputStream(args[1]));        Output out = new NormalOutput(doc);        out.dumpTo(os);        os.close();        docSource.close();


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/418610.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号