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?
Related
I have a website in asp.net and I am working on creating AMP pages at http://mywebsite.com/amp/......
I was able to make all the necessary changes for AMP except the following error.
The attribute 'action' may not appear in tag 'FORM [method=POST]'
the Form tag in my website looks like this
<form name="form1" method="post" id="form1">
AMP tutorial suggest to use action-xhr=/default.aspx instead of action="default.aspx
here is the source: https://ampbyexample.com/components/amp-form/
Now, the thing is how to remove action attribute and add action-xhr attribute in asp.net.
I tried following code in cs file but no luck.
this.Page.Form.Attributes.Remove("action");
Please note JavaScript and jQuery are not allowed in AMP
Take a look at the MSDN documentation, where it talks about an ActionlessForm. You basically inherit HtmlForm, and replace the form tag on the aspx page with your new control. You'll have to replace a bit of code like they suggest with the following:
base.Attributes.Remove("action");
writer.WriteAttribute("action-xhr", this.Action);
Worked like a charm for me. You may need to replace this.Action with this.Page.Request.Path, and you may find that you need to also add a target attribute, but this will definitely put you on the right path.
Add this script in the head tag (this will make your form to amp-form):
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
Now, your form can have action-xhr attribute.
<form name="form1" method="post" id="form1" action-xhr="__url__">
and
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.
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
Assume I have on a page an article with the possibility to comment it. I have a submit form that submits via ajax and the OnComplete javascript method intercepts the result of the form submit.
Each comment is smth like:
<div class="text">
<p class="details">
User Always_Dreaming at 01/01/2009 - 11:13:52 </p>
<p>Here goes my text :D</p>
</div>
I made an .ascx file from it, and I do tml.RenderPartial foreach comment. Now the question is how can I use this .ascx control to output the inserted content to the OnComplete method from client side.
PS. I want to use this approach and not to serialize the Comment object and to return the serialized data, take it wioth my js code and generate on the fly the html with data from the deserialized Comment object.
What you need to do is use the PartialViewResult from the action that's invoked by your javascript call. The client side code can append it to the html using something like the jQuery append or html method calls.
for those who are interested, I found a sample :)
here
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).