1

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

  • Are you completely sure your HTML is valid XML? (than your question should be "how to apply XSLT to an XML) Or you need HTML -> XML conversion first? Just to clarify "XSLT corresponding to HTML" is XSTL you want to apply to HTML, not XSLT used to construct HTML... – Alexei Levenkov Mar 08 '13 at 07:06
  • @Alexei Levenkov: I am sorry I had given in in wrong html, but I ve rectified it. Yes the current HTML is valid. As I ve mentioned, the exe XMLWrench gives me the xml, but I need a web solution. So I ve the HTML and its corresponding XSLT. –  Mar 08 '13 at 07:10
  • Seemingly duplicate question http://stackoverflow.com/questions/15288559/getting-xml-from-html-by-xslt ... Your description is somewhat confusing... If you can't answer if HTML is valid XML or not (instead of fixing it by hand), please at least explain how XSLT related to that HTML and resulting XML... – Alexei Levenkov Mar 08 '13 at 07:14
  • @AlexeiLevenkov: The question seems to be same but both are posted almost at the same time, just a coincidence i suppose. But I am sorry if my question is confusing. This is the sitution, I created a html form corresponding to a particular XSLT and XML, I hope thats clear, now I need to edit this form so basically this change should be reflected in the xml too. Does that make sence? –  Mar 08 '13 at 07:24
  • Get it now - I was considering it as generic HTML/XSLT/XML question, but it is very specific to system you are using. Most likly it is very similar to InfoPath implementation I worked some years on - so you should be able to figure mapping of named HTML elements back to XML. – Alexei Levenkov Mar 08 '13 at 17:54

3 Answers3

3

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.

Nimmi
  • 680
  • 8
  • 18
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.

Charles Wesley
  • 828
  • 12
  • 27
  • I get that, but I am looking forward to create a smart form XML from a non Ektron site, ie, once I create this XML I can use it to add it as content in the Ektron site later. –  Mar 11 '13 at 05:44
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.

Community
  • 1
  • 1
Spongeboy
  • 2,232
  • 3
  • 28
  • 37
  • +1: I tried the parsing of html. But Ektron has other controls like calander, link,resources, etc, which I am not able to manage. it is possible, but is there any easier way. more like how Ektron does it actually. –  Mar 14 '13 at 05:17