string转为document 根据需要不同转法 动态表单解析设计表单的内容
2015-05-07 14:25
357 查看
对于实现动态表单设计的表单时写在textare中的,因此需要进行解析
获取里面的输入框,(此时前台js解析不了,页面可能过于复杂,前台无法解析)
本人需要解析后的内容,供参考
进行一系列操作之后,需要展示表单,此时用java解析后传到前台总会少一部分的内容,所有改到前台解析
至于动态表单,本人是根据输入框id存入到数据库动态修改表结构,读取时也是动态读取的,供参考
获取里面的输入框,(此时前台js解析不了,页面可能过于复杂,前台无法解析)
/** * String 转换为 Document 对象 * * @param xml 字符串 * @return Document 对象 */ public static Document string2Doc(String xml) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; Document doc = null; InputSource source = null; StringReader reader = null; try { builder = factory.newDocumentBuilder(); reader = new StringReader(xml); source = new InputSource(reader);//使用字符流创建新的输入源 doc = builder.parse(source); return doc; } catch (Exception e) { return null; } finally { if(reader != null){ reader.close(); } } }
本人需要解析后的内容,供参考
Document doc = OperateXMLByDOM.string2Doc("<html><body>"+formModel.getModelStyle().replaceAll(" ", " ")+"</body></html>"); //解析text NodeList textList = doc.getElementsByTagName("input"); 2015/5/7 for(int i = 0;i<textList.getLength();i++){ Node n =textList.item(i); String proName; String proColumn = n.getAttributes().getNamedItem("name").getTextContent(); Node title = n.getAttributes().getNamedItem("title"); if(title == null){ proName = proColumn; }else{ proName = title.getTextContent(); } } //解析textarea NodeList areaList = doc.getElementsByTagName("textarea"); for(int i = 0;i<areaList.getLength();i++){ Node n =areaList.item(i); String proName; String proColumn = n.getAttributes().getNamedItem("id").getTextContent(); Node name = n.getAttributes().getNamedItem("title"); if(name == null){ proName = proColumn; }else{ proName = name.getTextContent(); } } //解析select NodeList selectList = doc.getElementsByTagName("select"); for(int i = 0;i<selectList.getLength();i++){ Node n =selectList.item(i); String proName; String proColumn = n.getAttributes().getNamedItem("id").getTextContent(); Node name = n.getAttributes().getNamedItem("title"); if(name == null){ proName = proColumn; }else{ proName = name.getTextContent(); } }
进行一系列操作之后,需要展示表单,此时用java解析后传到前台总会少一部分的内容,所有改到前台解析
<script type="text/javascript"> $(document).ready(function(){ //${nodes}是后台传来的数据 var nodes = eval("("+'${nodes}'+")"); var it = $("input,textarea,select"); for(var i = 0; i<it.length;i++){ var id = $("#"+it[i].id); id.replaceWith(nodes[it[i].id]); } }); </script>
至于动态表单,本人是根据输入框id存入到数据库动态修改表结构,读取时也是动态读取的,供参考
相关文章推荐
- SharePoint 2010 内容路由根据设置的Rule将Document 动态dispatch到不同的Library或是SubFolder中
- 根据需要动态include不同的文件
- 根据需要动态include不同的文件
- 根据不同的Json结构解析出Json的内容
- vf表单中如何根据组合框内容而选择不同文件再根据不同文件改变文本框的内容
- 17/4/2 js 表单(根据选项显示不同内容)
- JAVA生产报表导出成PDF格式(报表中的内容存储在String字符串中,需要解析,业务特殊)
- 根据需要动态include不同的文件
- 在表单设计中,我们需要注意哪些内容呢?
- cell的自适应 根据cell上面的内容 动态返回cell的高度 还有利用NSMutableAttributedString 做出效果
- Dom4j解析XML文本,遍历指定节点下的节点内容和属性,并存入List<Map<String,Object>
- 解析: Flex初始化时、加载进度监控的设计思路: (1)不同的Loader并行下载
- UITableViewCell根据内容显示不同的高度问题
- 如果网页内容需要支持多语言,你会怎么做?在设计和开发多语言网站时,有哪些问题你必须要考虑?
- php动态内容文件缓存的设计和高效实现
- 架构根据电信、网通用户自动解析不同IP的DNS服务器
- 在eos中当前人工活动需要根据条件走不同的分支
- select 动态改变显示不同内容
- jQuery 获取对象 根据属性、内容匹配, 还有表单元素匹配
- sqlserver触发器根据COLUMNS_UPDATED内容生成动态更新列