How to build a dynamic URL with ampersands - xquery

I have to build a dynamic url in XQuery. I have a hardcoded url. Part of the url should be built from a variable. How do I build that url? I am not able to use concat in XQuery because the first half of the url has special characters (ampersands).
The value ceiatlpaqer055.coxinc.com in the below url is dynamic and should be populated from a different variable. How Do I build this url in XQuery?
The URL is given below:
http://axiomweb604.testinc.com:8080/arsys/forms/axiom_7_6_4/SHR%3ALandingConsole/Default+Administrator+View/?mode=search&F304255500=AST:ComputerSystem&F1000000076=FormOpenNoAppList&F303647600=SearchTicketWithQual&F304255610=%27Name%27%3D%22ceiatlpaqer055.coxinc.com%22

& is a special character, so you have to escape it. Using the XML entity syntax this can be replaced by &. So you can in fact concat this string, e.g. by doing
"http://axiomweb604.testinc.com:8080/arsys/forms/axiom_7_6_4/SHR%3ALandingConsole/Default+Administrator+View/?mode=search&F304255500=AST:ComputerSystem&F1000000076=FormOpenNoAppList&F303647600=SearchTicketWithQual&F304255610=%27Name%27%3D%22" || "ceiatlpaqer055.coxinc.com" || "%22"
or
concat("http://axiomweb604.testinc.com:8080/arsys/forms/axiom_7_6_4/SHR%3ALandingConsole/Default+Administrator+View/?mode=search&F304255500=AST:ComputerSystem&F1000000076=FormOpenNoAppList&F303647600=SearchTicketWithQual&F304255610=%27Name%27%3D%22", "ceiatlpaqer055.coxinc.com", "%22")

Related

Is it better to use a "?" or a ";" in a URL?

In my application, I redirect an HTTP request and also pass a parameter. Example:
http://localhost:9000/home;signup=error
Is it better to use a ; or shall I use a ? i.e. shall I do http://localhost:9000/home;signup=error or http://localhost:9000/home?signup=error?
Are the above two different from each other semantically?
The ? is a reserved character; I have read that this is both valid and invalid, but I have used it for 'slugs' when templating.
Should you choose to use it, percent-encode the query string using %3F which is not human readable, but will produce the ?. (An encoder is recommended)
Perhaps you will find a more suitable solution for your redirects by adding an .htaccess file to your project.

How to handle ampersand in URL string with more parameters as a value

I'm trying to send ampersand as a value of one of the url parameter but without any success.
Response.Redirect(String.Format("WebForm.aspx?P1=&P2=&P3="));
E.g. "WebForm.aspx?P1=John&P2=Smith&P3=Del&Company" returns John Smith Del. So everything after ampersand as a value in url is trimmed.
Is there any trick how to handle this issue.
Note: The url is feeded by parameters from somewhere else.
Have you tried to replace the & with &?
How can I add an ampersand for a value in a ASP.net/C# app config file value

Response Parsed Body in Paw. How to identify the Key-Path in a long url?

I have a Paw related question.
Does anybody know how to extract a value from an encoded URL response field with Paw? The value is the only part of the encoded URL which starts with a %3D (the URL encoded version of an = sign).
Getting the dynamic values out of JSON, a JSON array, a URL, etc worked great.
You can use our RegExp Match dynamic value for this: https://luckymarmot.com/paw/extensions/RegExMatch
insert the RegExp Match dynamic value first
as input for RegExp Match use the Response Parsed Body dynamic value (with the key path to the url-encoded field with the id)
write the regular expression to extract the id from the field (see example in the screenshot)
Excellent point Natalia. Instead of the Regex extension I used the Substring extension. This worked perfectly as the size of the encoded URL never changed.

How to configure jsdom to preserve tag name case?

Look at these lines:
var doc = jsdom.jsdom("<moshe></moshe>");
console.log(doc.childNodes[0].tagName);
The second line writes "MOSHE" to the console in uppercase that means jsdom recognized my string as HTML and not XML. How can I enforce jsdom to preserve tag name original case?
Thanks in advance.
According to the HTML standard tagName is supposed to be uppercase in a HTML document.
The tagName attribute must run these steps:
If context object's namespace prefix is not null, let qualified name be its namespace prefix, followed by a ":" (U+003A), followed by its local name. Otherwise, let qualified name be its local name.
If the context object is in the HTML namespace and its node document
is an HTML document, let qualified name be converted to ASCII
uppercase.
Return qualified name.
Jsdom currently does not support XML documents (officially), since there's no differentiation internally between a HTML and XML document.
To parse as XML in v1.0+ you have to provide htmlparser2 as the parser, jsdom then implies parsing as XML based on a <?xml directive. This might become unnecessary if #883 gets merged, in which case a parsingMode option will be introduced, which accepts "xml" and switches to a xml parser.
Ultimately, work is underway to go about this problem, however an immediate solution to parsing XML with jsdom is not in sight.

Regular expression to replace & with & in XML file

In an XML file, I am capturing a long list of URLS from a web page, using regex (in .NET). Within the captured URLS, I simply need to substitute '&' for all '&' that are located within the URLS. How do I do this?
If you do this and save the results, you'll be left with invalid xml. If you are using a real xml parser the & will be correctly returned as & at the time you read it.
If you insist on proceeding, a simple String.Replace("&", "&") on each url should suffice.
Rather than a regex I'd suggest using the String.Replace("&","&") string function.
Why don't you do just:
string.Join("\n", System.IO.File.ReadAllLines("file.txt")).Replace("&", "&");
?

Resources