I am looking for solution where I can convert a html into xml based on an xslt. For example:
我正在寻找一种可以基于xslt将html转换为xml的解决方案。例如:
html:[this is a html from ektron(a CMS)]
html:[这是来自ektron(一个CMS)的html]
<p>Name: <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" /> 
</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" /> </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" /> </p>
<p> 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;"> </span><br /><br /> </p>
I have its corresponding XSLT at hand.
我手边有相应的XSLT。
From both these I want an XML as following
从这两个方面,我想要一个XML。
<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.
我找到了一个可以实现这个功能的应用程序XMLWrench,但是我需要一个c# .net解决方案,更像一个API或其他东西。
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
编辑II:我还需要表单中的值,以便在xml中添加。如果这些文本框中存在一个名称,那么应该将其添加到xml节点中
3 个解决方案
#1
1
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.
如果您确实需要使用HTML -> XML页面,那么我将使用HTML解析器,然后以编程方式创建XML。或者,如果这样做,那么可以跳过XSLT/XML阶段,只构建输出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).
然而,这个问题表明你使用了错误的方法,我同意查尔斯·韦斯利的答案——使用聪明的形式。Ektron HTML表单用于简单的数据收集,其中数据可以导出到Excel(例如简单的注册表单)。
Smart Forms are stored as XML. You can create Smart Forms via the Ektron API.
智能表单以XML的形式存储。您可以通过Ektron API创建智能表单。
Here is an eGandalf blog post on combining Smart Forms and Ektron HTML forms that might be useful.
下面是一篇eGandalf的博客文章,介绍了如何将智能表单和Ektron HTML表单结合起来,这样可能会很有用。
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.
编辑以回应评论-它仍然听起来好像你在走错误的道路,并试图工作反对埃克特朗。或者看看api ?例如,对于日历项,您可以使用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).
你评论说,你希望找到一个“更像埃克特朗的解决方案”。Ektron使用XSLT将XML转换成HTML,而不是反过来。您应该使用智能表单或API来将结构化数据作为XML。HTML内容应该不需要或最少的转换(如果需要转换HTML, XSLT不是解决方案)。
Please read over eGandalf's blog post on saving a form submission as a Smart Form. I think this covers your situation.
请阅读eGandalf关于将表单提交保存为智能表单的博客文章。我想这可以解决你的问题。
#2
3
If you are asking about the html for smartform configuration html you can use the following methods.
如果您正在询问关于smartform配置html的html,您可以使用以下方法。
Use LoadPackage(m_refContApi, editorPackage) and TransformXsltPackage methods in ContentDesignerWithValidator.ascx to convert html to xml.This page is located in /Workarea/controls/Editor/ContentDesignerWithValidator.ascx
在ContentDesignerWithValidator中使用LoadPackage(m_refContApi、editorPackage)和TransformXsltPackage方法。ascx将html转换为xml。这个页面位于/Workarea/controls/Editor/ContentDesignerWithValidator.ascx中
try this.
试试这个。
#3
2
If you are using Ektron then you can use a SmartForm which allows you to create the web form UI for the content editor but it saves the data as XML. To access the XML, just retrieve the ContentData object and you will note that the html property of the object is XML.
如果您正在使用Ektron,那么您可以使用SmartForm,它允许您为内容编辑器创建web form UI,但它将数据保存为XML。要访问XML,只需检索ContentData对象,您将注意到该对象的html属性是XML。
#1
1
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.
如果您确实需要使用HTML -> XML页面,那么我将使用HTML解析器,然后以编程方式创建XML。或者,如果这样做,那么可以跳过XSLT/XML阶段,只构建输出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).
然而,这个问题表明你使用了错误的方法,我同意查尔斯·韦斯利的答案——使用聪明的形式。Ektron HTML表单用于简单的数据收集,其中数据可以导出到Excel(例如简单的注册表单)。
Smart Forms are stored as XML. You can create Smart Forms via the Ektron API.
智能表单以XML的形式存储。您可以通过Ektron API创建智能表单。
Here is an eGandalf blog post on combining Smart Forms and Ektron HTML forms that might be useful.
下面是一篇eGandalf的博客文章,介绍了如何将智能表单和Ektron HTML表单结合起来,这样可能会很有用。
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.
编辑以回应评论-它仍然听起来好像你在走错误的道路,并试图工作反对埃克特朗。或者看看api ?例如,对于日历项,您可以使用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).
你评论说,你希望找到一个“更像埃克特朗的解决方案”。Ektron使用XSLT将XML转换成HTML,而不是反过来。您应该使用智能表单或API来将结构化数据作为XML。HTML内容应该不需要或最少的转换(如果需要转换HTML, XSLT不是解决方案)。
Please read over eGandalf's blog post on saving a form submission as a Smart Form. I think this covers your situation.
请阅读eGandalf关于将表单提交保存为智能表单的博客文章。我想这可以解决你的问题。
#2
3
If you are asking about the html for smartform configuration html you can use the following methods.
如果您正在询问关于smartform配置html的html,您可以使用以下方法。
Use LoadPackage(m_refContApi, editorPackage) and TransformXsltPackage methods in ContentDesignerWithValidator.ascx to convert html to xml.This page is located in /Workarea/controls/Editor/ContentDesignerWithValidator.ascx
在ContentDesignerWithValidator中使用LoadPackage(m_refContApi、editorPackage)和TransformXsltPackage方法。ascx将html转换为xml。这个页面位于/Workarea/controls/Editor/ContentDesignerWithValidator.ascx中
try this.
试试这个。
#3
2
If you are using Ektron then you can use a SmartForm which allows you to create the web form UI for the content editor but it saves the data as XML. To access the XML, just retrieve the ContentData object and you will note that the html property of the object is XML.
如果您正在使用Ektron,那么您可以使用SmartForm,它允许您为内容编辑器创建web form UI,但它将数据保存为XML。要访问XML,只需检索ContentData对象,您将注意到该对象的html属性是XML。