Convert HTML to XML according to the XSLT

限于喜欢 提交于 2019-12-13 02:38:02

问题


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


回答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.

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.




回答2:


If you are asking about the html for smartform configuration html you can use the following methods.

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

try this.




回答3:


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.



来源:https://stackoverflow.com/questions/15288496/convert-html-to-xml-according-to-the-xslt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!