I am trying to read webpage text by using Xml Document:
XmlDocument document = new XmlDocument();
string site = "https://emailhunter.co/search/a-bs.com";
document.Load(site);
string allText = document.InnerText;
This is the exception i get:
An unhandled exception of type 'System.Xml.XmlException' occurred in System.Xml.dll
Additional information: The ';' character, hexadecimal value 0x3B, cannot be included in a name. Line 5, position 383.
I really don't understand what's wrong here. If you can give me some tips, I would really appreciate it.
You can use the Html Agility Pack like written in this post: What is the best way to parse html in C#?
Related
When I try to send a document, an error will be generated.
Error calling CreateEnvelope: {"errorCode":"NO_DOCUMENT_RECEIVED","message":"The document element did not contain the encoded document, or there is a problem with the encoding. No documents were found in the request."}
I have already searched the internet but I can't find anything, can anyone help me.
You can find examples of how to use Base64 encoding to pass the document bytes to the eSignature REST API using the C# eSignature SDK
https://github.com/docusign/code-examples-csharp/blob/master/launcher-csharp/eSignature/Examples/SigningViaEmail.cs
Here is the relevant C# Code:
// Create document objects, one per document
Document doc1 = new Document();
string b64 = Convert.ToBase64String(Document1(signerEmail, signerName, ccEmail, ccName));
doc1.DocumentBase64 = b64;
doc1.Name = "Order acknowledgement"; // can be different from actual file name
doc1.FileExtension = "html"; // Source data format. Signed docs are always pdf.
doc1.DocumentId = "1"; // a label used to reference the doc
I am working on a project in visual studio that imports a CSV, and exports an XML file. I'd like to be able be able to get the code to work as XML and HTML, and view it in a browser. I am getting this error when I load the XML file into a browser:
Firefox
XML Parsing Error: not well-formed
Location: file:///C:/Users/fenwky/XmlDoc.xml
Line Number 2, Column 6:<?xsl:stylesheet <abc:stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">?>
Chrome
This page contains the following errors: error on line 2 at column 16: colon are forbidden from PI names 'xsl:transform'
This is what my c# code looks like in visual studio 2013:
// Create a procesing instruction.
XmlProcessingInstruction newPI;
// Stylesheet
String PItext = "<abc:stylesheet xmlns:abc=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">";
newPI = doc.CreateProcessingInstruction("abc:stylesheet", PItext);
doc.InsertAfter(newPI, doc.FirstChild);
// Save document
doc.Save(xmlfilename);
If you are trying to insert an processing instruction into the XML, the data parameter of the CreateProcessingInstruction method does not need to contain the name of the processing instruction in this case. In other words you just need to do this...
var PItext = "xmlns:abc=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"";
var newPI = doc.CreateProcessingInstruction("abc:stylesheet", PItext);
doc.InsertAfter(newPI, doc.FirstChild);
However, I am wondering why you are trying to add this particular processing instruction to an XML document. Perhaps you mean to link an XML document to a separate XSLT document, so it will be transformed if read by a browser?
If so, you probably need to be doing this...
var piText = "type=\"text/xsl\" href=\"style1.xsl\"";
var newPI = doc.CreateProcessingInstruction("xml-stylesheet", piText);
doc.InsertAfter(newPI, doc.FirstChild);
This will write the following processing instruction to the XML, which can then be read by the browser:
<?xml-stylesheet type="text/xsl" href="style1.xsl"?>
I’m building a Windows 8 app in C# to show RSS feeds into the App http://blogs.msdn.com/b/jasonz/rss.aspx . This works fine when I’m reading the RSS feed and convert all content to text and bind all the feed items to the XAML properties. The next step was to convert the (x)HTML to XAML so the layout and markup would be translated and shown in a RichTextBlock.
To accomplish that I’m using this code ( https://github.com/MacawNL/WinRT-RichTextBlock.Html2Xaml ) to bind and convert html to xaml to a RichTextBlock. Which seems to work fine when I’m using a string var with some sample HTML in it. var content = “test and test number two”; Also the test and example strings work fine.
But as soon as I try to put my RSS feed content (with (x)HTML) into the WinRt-RichTechtBlock.Html2Xaml I get an exception error on this line: xhtmlDoc.LoadXml(xhtml); in RichTextBlockProperties.cs .
This is the Exception Error
An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code Additional information: Value does not fall within the expected range.
I’ve been trying to find a way to parse / load my downloaded content from the RSS feed into the xhtmlDoc.LoadXml function but with no success.
How can i get WinRT-RichTextBlock.Html2Xaml to understand the content from the RSS feed to it can convert the HTML to the correct XAML tag?
Update
The xHTML could indeed be invalid (as you can see when you look at the RSSfeed) it's just some parts of HTML not the whole document). But I want to ignore those errors, and handle the correct ones it can find.
The error was because of invalid HTML. As soon as I stripped the invalid parts (e.g. target=_blank vs target="_blank" ) the exception error disappeared.
I am using the following code to read live xml url.
XmlDataDocument xmlDoc = new XmlDataDocument();
xmlDoc.Load("http://deluxecomm.com.au/feed.php");
I am getting the following error
Getting Error "Additional information: Reference to undeclared entity 'acirc'. Line 3325, position 145."
What I am doing wrong here!!!
You are trying to read HTML into an XML Data Document. HTML is not XML. They are both markup languages, but the two are not interchangeable.
You should look into using the HTML Agility Pack
I have an & character in one of the xml nodes as below.
<dependents>9 & 5</dependents>
When I try to load the file as below, it is giving an error "An error occured while parsing EntityName.". Is it possible to escape this character and load successfully? Thank you.
m_InputXMLDoc = new XmlDocument();
if (System.IO.File.Exists(InputFile))
{
m_InputXMLDoc.Load(InputFile);
}
Your XML is invalid.
You need to change it to &.
Use a CDATA section
<dependents><![CDATA[9 & 5]]></dependents>