根据XSLT将HTML转换为XML [英] Convert HTML to XML according to the XSLT

查看:108
本文介绍了根据XSLT将HTML转换为XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找解决方案,我可以根据xslt将html转换为xml。
例如:

html:[这是ektron(CMS)的一个html]

 < p>名称:&#160;< input type =textname =txtNameid =txtNameektdesignns_caption =txtNameektdesignns_name =txtNametitle =txtNameektdesignns_indexed =falseektdesignns_nodetype =elementstyle =size =24class =design_textfieldvalue =Enter Name/>&#160; 
< / p>

< p>年龄:< input type =textname =txtAgeid =txtAgeektdesignns_caption =txtAgeektdesignns_name =txtAgetitle =txtAgeektdesignns_indexed = falseektdesignns_nodetype =elementstyle =size =24class =design_textfield/>&#160;< / p>

< p>位置:< input type =textname =txtPlaceid =txtPlaceektdesignns_caption =txtPlaceektdesignns_name =txtPlacetitle =txtPlaceektdesignns_indexed = falseektdesignns_nodetype =elementstyle =size =24class =design_textfield/>&#160;< / p>
$ b $ p< p&#160;性别:< select name =rbSexektdesignns_maxoccurs =1size =1id =rbSexektdesignns_caption =rbSexektdesignns_name = rbSextitle =rbSexektdesignns_indexed =trueektdesignns_nodetype =elementstyle =>
< option selected =selectedvalue =0>(Select)< / option>
< option value =男>男< / option>
< option value =女性>女性< / option>
< span style =font-size:12px; line-height:0;>&#160;< / span>< br />< br / >&安培;#160;< / p为H.

我手边有相应的XSLT。

从这两个我想要一个XML如下

 < root> 
< txtName> DemoName< / txtName>
< txtAge> 21< / txtAge>
< txtPlace>英国< / txtPlace>
< rbSex>女性< / rbSex>
< / root>

我发现了一个可以执行此功能的应用程序XMLWrench,但我需要一个C#.net解决方案,更像一个API或其他东西。



编辑二:我也需要表单中的值,以便在xml.eg中添加:If这些在名称文本框中存在一个名称,这应该被添加到xml节点中。如果你真的必须去HTML - > XML页面,然后我会使用一个HTML解析器,然后以编程方式创建XML。另外,如果你这样做,那么你可以跳过XSLT / XML阶段,然后构建你的输出XML。



然而,这个问题表明你正在使用错误的方法,并且我同意 Charles Wesley的回答 - 使用智能表格。 Ektron HTML表单适用于简单的数据收集,只要将数据导出到Excel就足够了(例如简单的注册表单)。

智能表单存储为XML。您可以通过Ektron API创建Smart Forms。



这里是一个eGandalf博客文章,将Smart Forms和Ektron HTML表单结合起来可能会有用。

编辑回应评论 -
它仍然听起来像是你走错了路,试图对付Ektron。也许看看APIs?例如。对于日历项目,您可以使用日历API



您评论说您希望获得解决方案更像Ektron实际上是如何实现的。 Ektron使用XSLT将XML转换为HTML,而不是。您应该使用Smart Forms或API将您的结构化数据作为XML。 HTML内容应该不需要或者很少的转换(并且如果需要转换HTML,XSLT不是解决方案)。

请仔细阅读 eGandalf的博客文章将表单提交保存为智能表单。我认为这涵盖了你的情况。


I am looking for solution where I can convert a html into xml based on an xslt. For example:

html:[this is a html from ektron(a CMS)]

<p>Name:&#160;<input type="text" name="txtName" id="txtName" ektdesignns_caption="txtName" ektdesignns_name="txtName" title="txtName" ektdesignns_indexed="false" ektdesignns_nodetype="element" style="" size="24" class="design_textfield" value="Enter Name" />&#160;
</p>

<p>Age:<input type="text" name="txtAge" id="txtAge" ektdesignns_caption="txtAge" ektdesignns_name="txtAge" title="txtAge" ektdesignns_indexed="false" ektdesignns_nodetype="element" style="" size="24" class="design_textfield" />&#160;</p>

<p>Place:<input type="text" name="txtPlace" id="txtPlace" ektdesignns_caption="txtPlace" ektdesignns_name="txtPlace" title="txtPlace" ektdesignns_indexed="false" ektdesignns_nodetype="element" style="" size="24" class="design_textfield" />&#160;</p>

<p>&#160;Sex:<select name="rbSex" ektdesignns_maxoccurs="1" size="1" id="rbSex" ektdesignns_caption="rbSex" ektdesignns_name="rbSex" title="rbSex " ektdesignns_indexed="true" ektdesignns_nodetype="element" style="">
    <option selected="selected" value="0">(Select)</option>
    <option value="Male">Male</option>
    <option value="Female">Female</option>
    </select><span style="font-size: 12px; line-height: 0;">&#160;</span><br /><br />&#160;</p>

I have its corresponding XSLT at hand.

From both these I want an XML as following

<root>
  <txtName>DemoName</txtName>
  <txtAge>21</txtAge>
  <txtPlace>UK</txtPlace>
  <rbSex>Female</rbSex>
</root>

I found an application XMLWrench that does this functionality, but I need a C#.net solution, more like an API or something.

Edit II: I also need the values in the form too, to be added in the xml.eg: If these exists a name in the name textbox, this should be added into the xml node

解决方案

If you really have to go the HTML -> XML page, then I would use a HTML parser, and then programatically create the XML. Alternatively, if you do this then you can skip the XSLT/XML stage, and just build your output XML.

However, this question suggests that you are using the wrong approach, and I agree with Charles Wesley's answer - use a Smart Form. Ektron HTML forms are for simple data collection, where it is sufficient that the data can be exported to Excel (e.g. simple sign-up forms).

Smart Forms are stored as XML. You can create Smart Forms via the Ektron API.

Here is an eGandalf blog post on combining Smart Forms and Ektron HTML forms that might be useful.

Edit in response to comment- It still sounds like you are following the wrong path and trying to work against Ektron. Maybe have a look at the APIs? E.g. for calendar items you can use the calendar API.

You comment that you wish for a solution "more like how Ektron does it actually". Ektron uses XSLT to transform XML into HTML, not the other way around. You should use Smart Forms or API to get your structured data as XML. HTML content should require no or minimal transforming (and if transforming of HTML is required, XSLT is not the solution).

Please read over eGandalf's blog post on saving a form submission as a Smart Form. I think this covers your situation.

这篇关于根据XSLT将HTML转换为XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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