Better way to load a XML [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am reading a XMl and using it for some processing in my application.
var config = XElement.Load("c:/sample.xml");
Is there anyway to do load it in a better way? it takes a while while trying to process this line of code.

Look at XmlReader class, it provides fast, noncached, forward-only access to XML data.

You use so call DOM model of loading document which loads the whole XML. An alternative is a SAX model when you read data in consecutive manner. The API for that is XmlReader

Related

How to search and extract text from html file? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a bunch of 40k lines HTML files and I need to extract only sentences from it, so I want to automate this process. Text is located inside such blocks
<div class="text">...</div>
How do I search for these blocks and extract data between them to another file?
If the files are truly HTML files (e.g. They are the source of an actual webpage). Your best bet is to use HtmlAgilityPack which, despite it's age, is still incredibly robust (https://html-agility-pack.net/).
Your code to load the file and get all divs with the class of text would be :
var doc = new HtmlDocument();
doc.Load(filePath);
doc.DocumentNode.SelectNodes("//div[#class='text']");
SelectNodes simply takes an XPath string so it's easy enough to manipulate and the documentation is pretty good!

C# deserialize special data [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I create a function in c# to query ikea tradfri, here the result :
"<//15001/65536>;ct=0;obs,<//15001/65537>;ct=0;obs,<//15004/136834>;ct=0;obs,<//15005/136834/217609>;ct=0;obs,<//15005/136834/218326>;ct=0;obs,<//15005/136834/224384>;ct=0;obs,<//15005/136834>;ct=0;obs,<//15001>;ct=0;obs,<//15001/reset>;ct=0,<//status>;ct=0;obs,<//15005>;ct=0;obs,<//15004>;ct=0;obs,<//15004/add>;ct=0,<//15004/remove>;ct=0,<//15006>;ct=0;obs,<//15011/15012>;ct=0;obs,<//15011/9034>;ct=0,<//15011/9030>;ct=0,<//15011/9031>;ct=0,<//15011/9063>;ct=0,<//15011/9033>;ct=0,<//15010>;ct=0;obs"
Now I need to isolate everything that start with //15001/
I try JavaScript serializer or Newsoft but I don't achieve to get everything in order to go through.
Do you have tips to deserialize this kind of data in c# ?
thank for your help !
It looks like you are trying to query a CoAP service/endpoint. Awesome stuff, fortunately theres already open source implementations of the CoAP standard, including resource parsing, URI resolution, among others.
Here's a C# library that's linked from the CoAP Wiki page

Efficient way to extract key values using C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
We get token key values in the following format shown below. What is the efficient way to extract the amount and currency code key values?. I am trying to use Split method but not sure if that is the best way.
"{\"Amount\":12.0,\"CurrencyCode\":\"840\"}"
use JSON.NET http://www.newtonsoft.com/json . Is a popular JSON parser for .NET. You can call JObject.Parse ("yourtext"); and then you can inspect your JSON. For documentation, please follow this link http://www.newtonsoft.com/json/help/html/Introduction.htm.
Happy coding!

how read and write to stylesheet in asp.net mvc? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to let my users edit css files.
so I need to load (Read) one of my stylesheets to a textarea and then save (write) it into same stylesheet,
how i can do it?
It's just a file containing plain text. Simply load its contents and then save it back.. Simple File methods should be ok, maybe implement some kind of a text highlighter to allow nicer editing.

Deserialize an XML file without loading it all in the memory [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 months ago.
Improve this question
Suppose that your application serializes objects using XmlSerializer. When another part of the application (e.g. an external service or another component) process that XML file, gets you back a huge XML file that is a serialization of a huge object.
Which are your approach in deserializing and processing that response without filling your server's memory?
I usually prefer to use the XmlSerializer, but when I have to fight against these monster, I have no bullet-proof solutions. I've read about XNode.ReadFrom, but I'm wondering if using this method I can accomplish like a streaming-deserialization.

Categories