0

I have a big xml file which is composed of multiple xml files. The file structure is like this.

<xml1>
</xml1>
<xml2>
</xml2>
<xml3>
</xml3>
.
.
<xmln>
</xmln>

I want to process each XML file by a LINQ statement but I am not sure how to extract each XML element individually from the file and continue the iteration until the end. I figured experts here would be able to give me the nudge I am looking for. My requirement is to extract the individual elements so i could load into a XDoc element for further processing and continue on through the subsequent elements. Any help on this would be greatly appreciated.

Thanks for reading!!

4
  • have you tried YourXmlDoc.GetElementByTagName("NameOfTag").InnerText Commented May 25, 2011 at 16:18
  • Is it actually a complete XML file in itself, or is it just XML elements with no single root? Commented May 25, 2011 at 16:20
  • its just a text file with xml elements Commented May 25, 2011 at 16:21
  • It was created a error log which contains xml elements! Commented May 25, 2011 at 16:46

3 Answers 3

2

Assuming each element is a valid XML, you can wrap your document in a top-level tag and then load it just fine:

<wrap>
  <xml1>
  </xml1>
  <xml2>
  </xml2>      
</wrap>
Sign up to request clarification or add additional context in comments.

1 Comment

Anton Gogolev I was able to make it a XML document, how would i go about iterating?
0

You can use the System.Xml reference, which includes a lot of built-in functionality, and it allows you to declare an XmlTextReader. More info here.

Comments

0

If this is an error log with individual well formed xml elements, you probably don't want to load it as an XMLDocument. A better option is to use an XPathDocument created with an XmlReader where the XmlReaderSettings specify ConformanceLevel.Fragment. Then you can use an XPathNavigator to access your elements and attributes as needed. See the third answer in this forum post for sample code.

...late by just a year and then some. :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.