将TransformerFactory和DocumentBuilderFactory Java代码转换为c#或vb.net [英] convert TransformerFactory and DocumentBuilderFactory Java code to c# or vb.net

查看:67
本文介绍了将TransformerFactory和DocumentBuilderFactory Java代码转换为c#或vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c#或vb.net中的封闭代码对于以下java代码是什么。



What will be the closed code in c# or vb.net to the below java code.

private String saveDOM(Node node) throws Exception {
                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer transformer = factory.newTransformer();

                DOMSource source = new DOMSource(node);
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                StreamResult result = new StreamResult(stream);
                transformer.transform(source, result);
                
                String tag = stream.toString();
                
                int pos = tag.indexOf("<" + node.getNodeName());
                tag = tag.substring(pos);
                
                return tag;
        }
        
        private Document loadDOM(String source) throws Exception {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                dbf.setValidating(false);
                dbf.setNamespaceAware(false);
                dbf.setIgnoringComments(false);
                dbf.setIgnoringElementContentWhitespace(false);
                dbf.setExpandEntityReferences(false);
                DocumentBuilder db = dbf.newDocumentBuilder();
                return db.parse(new InputSource(new StringReader("<body>" + source + "</body>")));
        }

推荐答案

这篇关于将TransformerFactory和DocumentBuilderFactory Java代码转换为c#或vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆