Hi i´m parsing aspx file to XML and i have this code:
if (lineLower.StartsWith("</asp:content>")) || (lineLower.StartsWith("</asp:Content>") && lineLower.EndsWith(">")))
{
temp += line.Replace(line, " ");
}
But this temp += line.Replace(line, " "); will just add a space before < /asp:content> instead of replacing it byt space.
Do i need to use different syntax?
First, you have this
if (lineLower.StartsWith("</asp:content>"))
You're closing your if too soon
Try this
if (lineLower.StartsWith("</asp:content>") || (lineLower.StartsWith("</asp:Content>") && lineLower.EndsWith(">"))
{
temp += line.Replace(line, " ");
}
You coded it way too complicated
Just do this:
if (line.ToLower().StartsWith("</asp:content>") && line.EndsWith(">")))
{
temp += " ";
}
Not even sure if you need this part : line.EndsWith(">")
Related
I currently have a method that appends two strings together based on the tag in an XML file that is being loaded. I would also like to add a unique key between these two strings for parsing reasons later. Below are examples of the way it is working now and what I would like it to do.
-CURRENT: strValue~&elem.text()~&
-GOAL: strValue~&elem.text()
// If the tag is "Tag" or "Building append its text to strValue (part of item name)
elem = elemTag.selectSingleNode("ofda:Type",nsmgr);
if(elem && (elem.text() == "Tag" || elem.text() == "Building"))
{
elem = elemTag.selectSingleNode("ofda:Value",nsmgr);
if(elem)
{
strValue += elem.text() + "~&";
}
}
strValue += strValue ? "~&" + elem.text() : elem.text(); ?
the code below is a cgi file and I am having problems displaying the image and style from an external css file. The code is in lines 18-28 and I'm not sure what I am doing wrong. I would appreciate any help.
#!/usr/bin/perl -w
use strict;
use DBI;
use CGI;
use CGI::Carp('fatalsToBrowser');
my $query = new CGI;
print $query->header();
my $my_database = "TrypSnoDB";
my $localhost = "localhost";
my $dsn = "DBI:mysql:$my_database:$localhost";
my $db_user_name = "adrian";
my $db_password = "temp_pass";
my $dbh = DBI->connect("DBI:mysql:database=TrypSnoDB;host=localhost;mysql_socket=/private/software/mysql/mysql.sock","adrian","temp_pass", {'RaiseError' => 1});
print "<html>\n";
print "<head>\n";
print "<title>Welcome to the T. Brucei snoRNA Database</title>\n";
print "<link type='text/css' rel='stylesheet' href='/public_html/style.css'>\n";
print "</head>\n";
print "<body>\n";
print "<h1>Trypanosomatid snoRNA Database</h1>\n";
print "<img class='my_images' src='/public_html/tb_pic1.png'>\n";
print "</body>\n";
print "</html>\n";
if ($query->param('submit1')){
my $orig_sno = $query->param('snorna1');
my $family = $query->param('family1');
my $query_type = $query->param('target_option1');
my $target = $query->param('target_name1');
if ($orig_sno eq "Trypanosoma brucei") {
$orig_sno = 1;
}
elsif ($orig_sno eq "Leishmania major") {
$orig_sno = 7;
}
elsif ($orig_sno eq "ALL") {
$orig_sno = "1 or ST.org_id=7";
}
if ($family eq "ALL") {
$family = "'C/D' or ST.family='H/ACA'";
}
else {
$family = "'$family'";
}
if ($target ne "ALL") {
$family = "$family and T.target_name='$target'";
}
my($db_query,$common_tar,$exp_ver_sno,$exp_ver_tar,$total);
$db_query = "SELECT ST.sno_name,T.target_name,T.location,T.base_pair,SM.annotated_seq FROM sno_Table ST,sno_Modifications SM,Targets T WHERE ST.sno_id=SM.sno_id and SM.mod_id=T.target_id and (ST.org_id=$orig_sno) and (ST.family=$family)";
$common_tar="and T.target_id in(SELECT T.target_id FROM sno_Table ST,sno_Modifications SM,Targets T WHERE ST.sno_id=SM.sno_id and SM.mod_id=T.target_id group by T.target_id having count(*)=2) order by T.location desc";
$exp_ver_sno="and ST.exper_ver='Y'";
$exp_ver_tar = "and T.exp_ver='Y'";
if ($query_type eq "snoRNAs with common targets") {
$db_query=$db_query.$common_tar;
}
elsif ($query_type eq "Experimentally verified snoRNAs") {
$db_query=$db_query.$exp_ver_sno;
}
elsif ($query_type eq "snoRNAs with experimentally verified targets") {
$db_query=$db_query.$exp_ver_tar;
}
elsif ($query_type eq "ALL"){
$db_query=$db_query;
}
my $sth = $dbh->prepare($db_query);
$sth->execute();
my$total = $sth->rows;
print "<table border=1>\n
<tr>
<th>snoRNA</th>\n
<th>Target Name</th>\n
<th>Target Location</th>\n
<th>Target Base Pair</th>\n
<th>Annotated Sequence</th>\n
</tr>\n";
while (my#row = $sth->fetchrow_array()){
my$sno_name = $row[0];
my$tar_name = $row[1];
my$tar_loc = $row[2];
my$tar_bp = $row[3];
my$annotated_seq = $row[4];
print "<tr>\n<td>$sno_name</td><td>$tar_name</td><td>$tar_loc</td><td>$tar_bp</td><td>$annotated_seq</td></tr>\n";
}
print "<tr>
<th>TOTAL</th>\n
<th>$total</th>\n
</tr>\n";
print "</table>";
}
Your problem is almost certainly that you have the wrong URL for the CSS file. You can confirm that by looking in the web server error log and seeing if there is a 404 record for the CSS request.
Unfortunately I can't tell you what the correct URL is as I have no idea how your web server is configured.
There are a couple of other issues that you might want to address though:
The HTML that you generate is invalid. You print the tags outside of the and tags. Printing raw HTML within your Perl program is a terrible idea - it's far too easy to make the kinds of errors that you have here. You would be far better advised to use a templating engine (I recommend the Template Toolkit).
Your database queries are prone to SQL injection attacks. Please switch to using bind variables before someone trashes your server.
this is in response to Dave Cross comment regarding the SQL statement building. To convert the statement build to use bindings appears to be fairly straightforward in order to prevent an SQL injection.
To use placeholder bindings I think the OP only needs to replace the variables $orig_sno and $family in the $db_query variable with the ? character. like so:
$db_query = "SELECT ST.sno_name,T.target_name,T.location,T.base_pair,SM.annotated_seq
FROM sno_Table ST,sno_Modifications SM,Targets T WHERE ST.sno_id=SM.sno_id and
SM.mod_id=T.target_id and (ST.org_id=?) and (ST.family=?)"; # one line
...
my $sth = $dbh->prepare($db_query);
$sth->execute($orig_sno, $family);
However as the $family variable is built possibly out of a previous conditional, a further variable $target is also in play.
if ($family eq "ALL") {
$family = "'C/D' or ST.family='H/ACA'";
}
else {
$family = "'$family'";
}
if ($target ne "ALL") {
$family = "$family and T.target_name='$target'";
}
Will the placeholder handle this interpolated variable? Or would the $target variable also require its own placeholder?
And is this all that would be required to do to deter would be SQL injection attacks in this case?
solved. If the $target variable did require its own place holder, a few adjustments to the conditionals would do the trick.
else {
$family = "'$family'";
}
# removed - if $target ne ALL conditonal
my($db_query,$common_tar,$exp_ver_sno,$exp_ver_tar,$total);
$db_query = "SELECT ... and (ST.org_id=?) and (ST.family=?)";
if ($target ne "ALL") {
$db_query =~ s/\)$//;
$db_query .= ' and T.target_name=?)';
}
$common_tar="and T.target_id ... ";
...
my $sth = $dbh->prepare($db_query);
if ($target ne 'ALL'){
$sth->execute($orig_sno, $family, $target);
else{
$sth->execute($orig_sno, $family);
}
I want to update the files which I uploaded to database
This is my query.. please help...
if (FileUpload1.HasFile || FileUpload2.HasFile || FileUpload3.HasFile || FileUpload4.HasFile || FileUpload5.HasFile)
{
string filename1 = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath("~/images/" + filename1));
string filename2 = Path.GetFileName(FileUpload2.PostedFile.FileName);
FileUpload2.SaveAs(Server.MapPath("~/images/" + filename2));
string filename3 = Path.GetFileName(FileUpload3.PostedFile.FileName);
FileUpload3.SaveAs(Server.MapPath("~/images/" + filename3));
//string filename4 = Path.GetFileName(FileUpload4.PostedFile.FileName);
//FileUpload4.SaveAs(Server.MapPath("~/images/" + filename4));
string filename5 = Path.GetFileName(FileUpload5.PostedFile.FileName);
FileUpload5.SaveAs(Server.MapPath("~/images/" + filename5));
}
even It is an old Topic....
But I have recently gotten same Error... The Error Try to access the pathe which is not available. Let me say as my example :
I Have a folder (Fa) which belongs to My Experts and The main Path where records upload files are In another folder (Fb)...
At First I wrote this Code :
string strname2;
strname2 = ("Fa/" + FileUpload2.PostedFile.FileName.Substring(FileUpload2.PostedFile.FileName.LastIndexOf("//") + 1));
LabelFile.Text = strname2;
and when I use Following Error I got that deadly Error :
if (strname2 != "Fa/")
{
FileUpload2.PostedFile.SaveAs(Server.MapPath(strname2));
}
else
{
LabelFile.Text = "";
}
After some test and try I change both above code to following Codes and Guess what? Everything works like a charm :
1:
string strname2;
strname2 = ("../Fb/Fa/" + FileUpload2.PostedFile.FileName.Substring(FileUpload2.PostedFile.FileName.LastIndexOf("//") + 1));
LabelFile.Text = strname2;
And then:
2:
if (strname2 != "../Fb/Fa/")
{
FileUpload2.PostedFile.SaveAs(Server.MapPath(strname2));
}
else
{
LabelFile.Text = "";
}
Now the solution is check your folders and see that folders are available or not.
PS: Search specially for this folder : NewThrissurDiary
Hope this Help you
We know F4F is Adobe's fragmented MP4 file format for HTTP Dynamic Streaming. A tool called F4F Packager could convert an F4V file to several F4F files and a manifest file(F4M).
My question is, how to convert such F4F files back to an F4V or MP4 file?
We finally found a simple method to merge & convert .f4f files -> .flv file, in which only 'mdat' box is usefull. Here is a the php code:
<?php
function ReadInt24($str, $pos)
{
return intval(bin2hex(substr($str, $pos, 3)), 16);
}
function ReadInt32($str, $pos)
{
return unpack("N", substr($str, $pos, 4))[1];
}
echo "\nKSV Adobe HDS Downloader\n\n";
$flvHeader = hex2bin("464c5601050000000900000000");
$firstVideoPacket = true;
$prevTagSize = 4;
$fragCount = 0;
isset($argv[1]) ? $baseFilename = $argv[1] : $baseFilename = "";
$baseFilename ? $outputFile = "$baseFilename.flv" : $outputFile = "Joined.flv";
while (true)
{
if (file_exists("$baseFilename" . $fragCount + 1 . ".f4f"))
$fragCount++;
else
break;
}
echo "Found $fragCount fragments\n";
$flv = fopen("$outputFile", "wb");
fwrite($flv, $flvHeader, 13);
for ($i = 1; $i <= $fragCount; $i++)
{
$frag = file_get_contents("$baseFilename$i.f4f");
preg_match('/(.{4})mdat[\x08\x09\x12]/i', $frag, $mdat, PREG_OFFSET_CAPTURE);
$fragLen = ReadInt32($mdat[1][0], 0) - 8;
$frag = substr($frag, $mdat[1][1] + 8, $fragLen);
$pos = 0;
while ($pos < $fragLen)
{
$packetType = $frag[$pos];
$packetSize = ReadInt24($frag, $pos + 1);
$packetTS = ReadInt24($frag, $pos + 4);
$totalTagLen = 11 + $packetSize + $prevTagSize;
if (($packetType == "\x08" && $packetSize > 4) or ($packetType == "\x09" && $packetSize > 40) or ($packetType == "\x09" && $firstVideoPacket))
{
if ($packetType == "\x09" && $firstVideoPacket)
$firstVideoPacket = false;
fwrite($flv, substr($frag, $pos, $totalTagLen), $totalTagLen);
}
$pos += $totalTagLen;
}
}
fclose($flv);
echo "Finished\n";
?>
A more comprehensive answer is available here : https://github.com/K-S-V/Scripts/blob/master/AdobeHDS.php.
The serious stuff happens around line 1046.
This script handles more cases that the current top answer. I won't post the whole script here since it's a bit long.
Alas, it's a PHP script too, though I may need to rewrite this in Java in a couple of weeks. If so, I'll post a link to the Java rewrite when it's done.
livestreamer and youtube-dl both support HDS streams. Here's an example of livestreamer:
$ livestreamer -O 'hds://radio_chym-lh.akamaihd.net/z/KIT967_1#183249/manifest.f4m' 48k >out.m4a
This is an internet radio station. For video, only a change in 48k and the file extension of out.m4a should be necessary.
what is an alternative for javascript escape function in c# for e.g suppose a string:"Hi Foster's i'm missing /you" will give "Hi%20Foster%27s%20i%27m%20missing%20/you" if we use javascript escape function, but what is the alternative for c#. i have searched for it but no use.
You can use:
string encoded = HttpUtility.JavaScriptStringEncode(str);
Note: You need at least ASP.NET 4.0 to run the above code.
var unescapedString = Microsoft.JScript.GlobalObject.unescape(yourEscapedString);
var escapedString = Microsoft.JScript.GlobalObject.escape(yourUnescapedString);
The best solution I've seen is mentioned on this blog - C#: Equivalent of JavaScript escape function by Kaushik Chakraborti. There is more to escaping javascript than simply url-encoding or replacing spaces with entities.
Following is the escape function implementation that you will find in Microsoft.JScript.dll...
[NotRecommended("escape"), JSFunction(JSFunctionAttributeEnum.None, JSBuiltin.Global_escape)]
public static string escape(string str)
{
string str2 = "0123456789ABCDEF";
int length = str.Length;
StringBuilder builder = new StringBuilder(length * 2);
int num3 = -1;
while (++num3 < length)
{
char ch = str[num3];
int num2 = ch;
if ((((0x41 > num2) || (num2 > 90)) &&
((0x61 > num2) || (num2 > 0x7a))) &&
((0x30 > num2) || (num2 > 0x39)))
{
switch (ch)
{
case '#':
case '*':
case '_':
case '+':
case '-':
case '.':
case '/':
goto Label_0125;
}
builder.Append('%');
if (num2 < 0x100)
{
builder.Append(str2[num2 / 0x10]);
ch = str2[num2 % 0x10];
}
else
{
builder.Append('u');
builder.Append(str2[(num2 >> 12) % 0x10]);
builder.Append(str2[(num2 >> 8) % 0x10]);
builder.Append(str2[(num2 >> 4) % 0x10]);
ch = str2[num2 % 0x10];
}
}
Label_0125:
builder.Append(ch);
}
return builder.ToString();
}
Code taken from Reflector.
The best solution I've seen is mentioned on this blog - C#: Equivalent of JavaScript escape function by Kaushik Chakraborti. There is more to escaping javascript than simply url-encoding or replacing spaces with entities.
I noticed another solution in the comments in KodeSharp article that may be better. The comment says it is more compatible with UTF-8 and does not require the reference to JScript. Is this better?
(Dependent on System.Web.Extensions.dll)
using System.Web.Script.Serialization;
JavaScriptSerializer serialiser = new JavaScriptSerializer();
serialiser.Serialize("some \"string\"")
string myString = "Hello my friend";
myString = myString.Replace(" ", "%20");
This would replace all " " with "%20".
Is this what you wanted?
You can try this
Uri.EscapeDataString(Obj);