Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
WebView2 ExecuteScriptAsync with XML input

I want to run a C# function using ExecuteScriptAsync() with XML text as input.

Something like that:

var xml = "<?xml version=\"1.0\" encoding=\"UTF - 16\" standalone=\"no\" ?><values>42</values>";
webView2Control.CoreWebView2.Navigate("file:///C:/Users/erezf/AppData/Local/Temp/index.html");
var input = "func(" + xml + ")";
await webView2Control.CoreWebView2.ExecuteScriptAsync(input);

The HTML file includes the function func:

<script id="test" type="text/javascript">
    function func(xml) { alert(xml); }
</script>

This code doesn't work, why?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Your XML string being passed to the Javascript function is missing single or double quotes. If you look at the input variable in the debugger, it will look like:

func(<?xml version="1.0" encoding="UTF - 16" standalone="no" ?><values>42</values>)

Simply add single quotes like this:

var xml = "'<?xml version=\"1.0\" encoding=\"UTF - 16\" standalone=\"no\" ?><values>42</values>'";
about 4 years ago · Santiago Trujillo Report

0

In my case the solution was:

1. add ' ' in the " ".
2. replace the "\n" with "\\n".
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!