xmlreader

Efficient way to read large XML into dfferent node types in C#

浪尽此生 提交于 2021-02-15 07:53:27
问题 I am new to C#. I have a relatively large XML file (28MB) and am trying to parse its subtrees into several different types based on their content. Essentially, I have 6900+ Content nodes that all have to be interrogated to figure out what type they are. <Collections> <Content>..</Content> <Content>..</Content> <Content>..</Content> ... </Collections> For each Content node, the variety of nodes below it can have 1 of 3 different patterns. I have to look into the node to decide which pattern

XmlReader read continually

久未见 提交于 2021-02-10 03:20:02
问题 I have a very large xml file. This is the simplified version of xml format. <?xml version='1.0' encoding='UTF-8'?> <Sender> <SenderID>571099948</SenderID> <Sponsors> <Sponsor> <SponsorID>TEST01</SponsorID> <Contracts> <Contract> <ContractID>000001</ContractID> <Member> <SSN>1111111111</SSN> <Gender>M</Gender> <Benefits> <Benefit BenefitType="AAA"> </Benefit> <Benefit BenefitType="BBB"> </Benefit> </Benefits> </Member> <Member> <SSN>4444444444</SSN> <Gender>F</Gender> <Benefits> <Benefit

XmlReader read continually

对着背影说爱祢 提交于 2021-02-10 03:16:11
问题 I have a very large xml file. This is the simplified version of xml format. <?xml version='1.0' encoding='UTF-8'?> <Sender> <SenderID>571099948</SenderID> <Sponsors> <Sponsor> <SponsorID>TEST01</SponsorID> <Contracts> <Contract> <ContractID>000001</ContractID> <Member> <SSN>1111111111</SSN> <Gender>M</Gender> <Benefits> <Benefit BenefitType="AAA"> </Benefit> <Benefit BenefitType="BBB"> </Benefit> </Benefits> </Member> <Member> <SSN>4444444444</SSN> <Gender>F</Gender> <Benefits> <Benefit

XMLReader: Get value of child node if another child node contains a special string

筅森魡賤 提交于 2020-02-08 08:28:35
问题 I have a XML structure (only a snippet) as follows: <ttOutput> <ttOutputRow> <cKey>key</cKey> <cValue>value</cValue> </ttOutputRow> <ttOutputRow> <cKey>findMe</cKey> <cValue>value</cValue> </ttOutputRow> <ttOutputRow> <cKey>key</cKey> <cValue>value</cValue> </ttOutputRow> </ttOutput> For this I want to use XMLReader to keep memory low. I'm looking for cValue if cKey is findMe . How can I get this value? This is what I tried: using (var stream = new StreamReader(path)) using (XmlReader reader

XMLReader: Get value of child node if another child node contains a special string

狂风中的少年 提交于 2020-02-08 08:26:26
问题 I have a XML structure (only a snippet) as follows: <ttOutput> <ttOutputRow> <cKey>key</cKey> <cValue>value</cValue> </ttOutputRow> <ttOutputRow> <cKey>findMe</cKey> <cValue>value</cValue> </ttOutputRow> <ttOutputRow> <cKey>key</cKey> <cValue>value</cValue> </ttOutputRow> </ttOutput> For this I want to use XMLReader to keep memory low. I'm looking for cValue if cKey is findMe . How can I get this value? This is what I tried: using (var stream = new StreamReader(path)) using (XmlReader reader

XmlReader throws multiple DTDs error

无人久伴 提交于 2020-02-06 03:22:43
问题 Let's say we want to load an xml (cXML) and validate it against a DTD that we have stored locally. Here's the code for this: XmlPreloadedResolver resolver = new XmlPreloadedResolver(XmlKnownDtds.None); resolver.Add(new Uri(DocTypeSystemId), File.ReadAllText(@"C:\cXml.dtd")); XmlReaderSettings settings = new XmlReaderSettings { ValidationType = ValidationType.DTD, DtdProcessing = DtdProcessing.Parse }; settings.ValidationEventHandler += Settings_ValidationEventHandler; XmlParserContext context

XmlReader - how to deal with large XML-Files?

自作多情 提交于 2020-01-16 13:23:04
问题 I was wondering how to deal with large and complex files in a XmlReader . In my case it's a pretty complex structure and I'm not okay with handling all of this inside a single-method. This is just too dirty in my opinion - so I tried to split the method into a few smaller methods. Therefore I started with the following code: // Create an XML reader for this file. using (var reader = XmlReader.Create(new StringReader(fileText))) { while (reader.Read()){ if (reader.IsStartElement(){ switch

parsing XML Data using c#

我与影子孤独终老i 提交于 2020-01-14 06:05:47
问题 I have been struggling with the XMLReaderClass in c# for some time now and just can't seem to get the concept. Basically I want to loop through the XML File and if the category in the xml doc is the same as the category I have passed it in, I want to add its name to a List. here is the xml <?xml version="1.0" encoding="utf-8" ?> <!-- Do not modify this xml file. --> <Products> <product category="Food" name="Baking potatoes" /> <product category="Food" name="Chicken fillet" /> <product

Why is my XML reader reading every other element?

為{幸葍}努か 提交于 2020-01-11 10:05:48
问题 I've built a very simple table that displays 4 columns and 4 rows. When the following code is executed it displays every other element in the .xml file. It does not discriminate per table row. It reads through without any problem and I have run xml validators so it not a syntax issue. public partial class lblXmlOutput : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel

Why is my XML reader reading every other element?

帅比萌擦擦* 提交于 2020-01-11 10:05:47
问题 I've built a very simple table that displays 4 columns and 4 rows. When the following code is executed it displays every other element in the .xml file. It does not discriminate per table row. It reads through without any problem and I have run xml validators so it not a syntax issue. public partial class lblXmlOutput : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel