简体   繁体   English

HTML Textarea 文本到 XML

[英]HTML Textarea text to XML

I have a HTML Textarea in which the list appears like this :我有一个 HTML Textarea,其中的列表如下所示:

jack=rider杰克=骑手

steven=conrad史蒂文=康拉德

nancy=gagan南希=加根

I have to create a button, which once pressed it should show the text in XML any way, In a file or in the same textbox.我必须创建一个按钮,一旦按下它应该以任何方式显示 XML 中的文本,在文件中或在同一个文本框中。

<list1>jack=rider</list1>

<list2>steven=conrad</list2>

and so on.等等。

The coding has to in javascript.编码必须在 javascript 中。 Please help.请帮忙。

I don't get completely this question, by the way if your aim was to turn a HTML document object, and whatever contents it has in XML, this is pretty straightforward if you have the right tools.我不完全明白这个问题,顺便说一下,如果您的目标是转换 HTML 文档对象,以及它在 XML 中包含的任何内容,如果您拥有正确的工具,这将非常简单。 We are using Wicked Google Xpath here, a pure JS implementation of the DOM Level 3 XPath specification.我们在这里使用Wicked Google Xpath ,它是 DOM Level 3 XPath 规范的纯 JS 实现。

So let's see how it works here, this can help you to build your contents from HTML code, but again, I'm not sure if this was your objective:所以让我们看看它在这里是如何工作的,这可以帮助您从 HTML 代码构建您的内容,但同样,我不确定这是否是您的目标:

 var console = { log: function(s) { document.getElementById("console").innerHTML += s + "<br/>" } } console.log("XML:installing parser..."); wgxpath.install(window) console.log("XML:Parser installed."); console.log("XML:Evaluating XPath..."); var expression = window.document.createExpression('//*[@id="contents"]'); console.log("XML:Evaluating XPath text"); var result = expression.evaluate(document, XPathResult.STRING_TYPE); console.log("XML:Contents <br><br>" + result.stringValue); console.log("<br><br>XML:DONE."); var expressionXML = window.document.createExpression('//*[@id="contents"]/node()'); console.log("XML:Evaluating XPath node()"); var resultXML = expression.evaluate(document, XPathResult.ANY_TYPE); console.log("XML:Contents <br><br>" + resultXML.iterateNext().textContent); console.log("<br><br>XML:DONE.");
 <script src="https://github.com/google/wicked-good-xpath/releases/download/1.3.0/wgxpath.install.js"></script> <div id="console" /> <div id="contents" style="display:none;"><textarea rows="4" cols="50"> At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies. </textarea> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM