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: <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.
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 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.
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.
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.
Related
I have to submit a HTTP POST request using a standard HTML Form element that contains one HTML input element which will contain the request XML.
This is the current code that I am trying with :
<form id="{CustomFormID}" method="post" name="{CustomFormName}" action="{TestHarness.aspx}">
<input type="text" id="inputData" name="inputData" value="{Request XML}"/>
I have created a function on Page_Load to build the request XML. The thing I want to know is, how can I pass that XML value through here.
Suggestions and hints are appreciated.
You can wrap the built XML with CData and use that in hidden field and post to required aspx page.
Syntax - <![CDATA[XML_VALUE]]>, replace XML_VALUE with actuals.
Similar answer posted here - Flash AS2: How to POST CDATA to a server?
I am beginning to study the very nice CMS Orchard and, after reading the basic documentation, I've stumbled in a little hurdle.
I've created a new DataType, 'SpecialOffer', which has some dataparts and some text datafields:
ProductName
PhotoURL
Price
Description
I've made a list, made a widget, customized the position.info file and the Views\Fields\Common.Text.cshtml file to change the position and the way the fields are rendered (a img for the photo, prepending € to the price and so on) but this doesn't give me the right amount of customization over the generated html.
I've installed the developer shape tracing module and created an alternate Content-SpecialOffer.cshtml file.
This gives me the opportunity to easily customize the HTML around the content, but I have no idea how to get to the single DataItem fields to display them the way I want.
I mean that the whole SpecialOffer object is displayed through
#Display(Model.Content )
and, exploring the model, I've not found a way to write something as, say (pseudocode)
<div>
the
<span class="name"> #Model.Contentitem.Fields["ProductName"]</span>
camera costs
#Model.Contentitem.Fields["Price"]
euros
</div>
I've read this post on SO
Custom View For RecentBlogPosts in Orchard
but it does not solves my problem, since it uses the standard properties of blogpost.
another little question: other than in the Documentation page of project orchard and b. LeRoy's http://weblogs.asp.net/bleroy/ where can I study Orchard?
Thanks!
Edit
I've found a way to do it:
#{
dynamic offer =Model.ContentItem.SpecialOffer;
}
<div>
the
<span class="name"> #offer.ProductName.Value</span>
camera costs
#offer.Price.Value
euros
</div>
is this the right way?
Yes, that's fine.
After the docs and the RSS feed on the home page of orchardproject.net, a major source of information (better than the previous 2) is the source code for the app and modules.
I currently have 2 JavaScript variables in which I need to retrieve values from. The HTML consists of a series of nested DIVs with no id/name attributes. Is it possible to retrieve the data from these variables using HTMLAgilityPack? If so how would I go about doing so, if not what would be required, regular expressions? If the latter, please help me in creating a regular expression that would allow me to do this. Thank you.
<div style="margin: 12px 0px;" align="left">
<script type="text/javascript">
variable1 = "var1";
variable2 = "var2";
</script>
</div>
I'm assuming you are trying to scrape this information from a website? Most likely one you don't have direct control over? There are several ways to do this, I'll go easy to hard( at least as I see em):
Ask the owner (of the site). Most of the time they can give you direct access to the information and if you ask nicely, they might just let you have it for free
You can use the webBrowser control, run the javascript and then parse values from the DOM afterwards. As opposed to HttpWebRequest, this allows for all the proper values to be loaded on the page and scraped. Helpful Link Here.
Steal the source with Firebug. Inspect the website with Firebug to see which URLs are called from the background. Most likely, its using an asynchronous request to retrieving the updated information from a webservice. Using Firebug, you can view this under the NET -> XHR. Look at the request and the values returned, you can then retrieve the values your self and parse the contents from the source rather than scrape the page.
I think this might be the information you were looking for, but if not let me know and I can clarify/fix answer
I'm importing some data from another test/bug tracking tool into tfs, and I would like to convert it's description, which is in simple HTML, so a plain string, where the 'layout' of the HTML is preserved.
For example:
<body>
<ol>
<li>Log on with user Acme & Co.</li>
<li>Navigate to the details tab</li>
<li>Check the official name</li>
</ol>
<br>
<br>
Expected Result:<br>
official name is filled in<br>
<br>
Actual Result:<br>
The &-sign is not shown correctly<br>
See attachement.
</body>
Would become plain text with newlines inserted and HTML-entities translated like:
1. Log on with user Acme & Co.
2. Navigate to the details tab
3. Check the official name
Expected Result:
official name is filled in
Actual Result:
The &-sign is not shown correctly
See attachment
I can currently replace some tags with newlines using a regex and strip the rest, but replacing the HTML-entities and stuff like <ol> and <ul> seemed like I'm re-inventing something (browser?). So I was wondering if someone has done this before me. I can't find it using Google.
Rather than regex, you could try loading it into the HTML agility pack? If it was xhtml, then an xslt transformation might be a good option.
In the end, once I got more comfortable with TFS, I customized the work item type to include a new HTML Field, and just copied the contents into that field.
This solution was so much better, because we could now see the intended formatting of the field.
I am writing some code that connects to a website, and using C#, and System.IO, reads the html file into my application, and then I continue to parse it.
What I am wanting to do now is, there is a drop down (combobox) on this site, that has 2 static values. I am wanting to have my code pick the 2nd option in the combo box and then parse the resulting html on the post back.
Any Ideas?
Ya the 2 selects are always the same.
Spamming software? Uh... No. It parses a video game website for player stats and I have full permission from the vendor to do so.
Yes I agree about the webservices, and they dont exist. I have already written the HTML parser and it works great. However, I need to pop this drop down for more data
I'd use HtmlAgilityPack and the HtmlAgilitypPack.AddOns.FormProcessor for that.
Say the code looks like this:
What color is your favorite?: <br/>
<form method="post" action="post.php">
<select name="color">
<option>AliceBlue</option>
<option>AntiqueWhite</option>
<option>Aqua</option>
</select><br/>
<input type="submit" value="Submit"/>
</form>
You would want to POST to post.php the argument "color" with the value "Aqua" (or whatever select value you want).