SgDotNet
Singapore Professional .NET User Group -For Cool Developers

XML Nightmare

rated by 0 users
This post has 8 Replies | 1 Follower

Top 200 Contributor
Posts 9
trinity Sad [:(] Posted: 01-02-2006 6:00 PM
Currently I'm using XMLReader to read the data in an XML file. I want to know is there a way to store the data that I had read on the file for reference anytime that I need to reference back anytime I want to get the details that I need to use.
Top 25 Contributor
Posts 154
i think so, you can use that getsinglenode or getnodes methods to retrieve the references you can use later
http://feelite.com/blog
Top 200 Contributor
Posts 9

The problem now is after I read through one xml file, I need to read in another to validate both data inside. Base on my data that I had compare if both are the same, I need to generate out a test script using my codes. That the part that I'm stuck with.As XMLTextreader is forward only reader, it can't read back to track what are the values previous to generate a test script.

I thought of storing all data in an array, but it seems to be a waste of computer resources. And XMLText reader is the best reader to use for now, as I need to handle large chunks of data in XML file.

Top 25 Contributor
Posts 154
 trinity wrote:

The problem now is after I read through one xml file, I need to read in another to validate both data inside. Base on my data that I had compare if both are the same, I need to generate out a test script using my codes. That the part that I'm stuck with.As XMLTextreader is forward only reader, it can't read back to track what are the values previous to generate a test script.

I thought of storing all data in an array, but it seems to be a waste of computer resources. And XMLText reader is the best reader to use for now, as I need to handle large chunks of data in XML file.



sorry for my first reply, it was totally out of context.

to make things clearers, can i say the following? it's hard to understand what you want to achieve, so it's better to refine the following input and output descriptions before looking at the implementation itself.

input: 2 xml documents
output: true if they are identical, false otherwise
http://feelite.com/blog
Top 25 Contributor
Posts 485
Hi,

If you need to store the xml data for referencing other than forward only reading, you can use XmlDocument, something like this:

  XmlDocument xmldoc= new XmlDocument();
  xml.Load(myreader); //myreader is your xml reader

Big Smile [:D]
Yes, another version, another round of headaches. But that's progress.
Top 200 Contributor
Posts 9

My first input is to have an xml schema in my codes to validate the xml test data file. The XML Test data file is used for generate value in my test cases later on. My second step was to pass in an dll file and get the various information in the dll file through reflection in .NET. The information that I got out was all the various methods, properties and classes name present in the dll file and I save it as an xml file.

At this point of time, I pass in the first xml file that had being validate by the xml schema, Using the xml text reader, I would check what are the various classes and methods present in the xml data file which had being generated out. If the classes and methods are present in the generated xml file, I would get the data present in the xml test data out to generate a test script for unit testing. The test script is almost simliar of writting a new class file just for testing purposes.

Currently, I'm using XMLTextReader to read both xml file. My generating of testscript is to use Streamwriter to generate. As my XmlTextReader read through the files of both XML, It would write out the test script in the StreamWriter is both methods and classes are present in the xml file. Currently what stop me in my codes is, how am I going to read back the data that I needed to generate the test script codes out again. As I need to make use of the various properties value and name to genarate the script.

I'm sorry if I had confuse you by my previous explations, because I'm confuse by my team mate with his requirements as well. Thanks you for your help. Hope that we could work out a solution soon.

Top 25 Contributor
Posts 154

 trinity wrote:

My first input is to have an xml schema in my codes to validate the xml test data file. The XML Test data file is used for generate value in my test cases later on. My second step was to pass in an dll file and get the various information in the dll file through reflection in .NET. The information that I got out was all the various methods, properties and classes name present in the dll file and I save it as an xml file.

At this point of time, I pass in the first xml file that had being validate by the xml schema, Using the xml text reader, I would check what are the various classes and methods present in the xml data file which had being generated out. If the classes and methods are present in the generated xml file, I would get the data present in the xml test data out to generate a test script for unit testing. The test script is almost simliar of writting a new class file just for testing purposes.

Currently, I'm using XMLTextReader to read both xml file. My generating of testscript is to use Streamwriter to generate. As my XmlTextReader read through the files of both XML, It would write out the test script in the StreamWriter is both methods and classes are present in the xml file. Currently what stop me in my codes is, how am I going to read back the data that I needed to generate the test script codes out again. As I need to make use of the various properties value and name to genarate the script.

I'm sorry if I had confuse you by my previous explations, because I'm confuse by my team mate with his requirements as well. Thanks you for your help. Hope that we could work out a solution soon.

a lot more information, but still in a mess. Here is my second try

input:

  • 1 XML schema file
  • 1 XML test data file
  • 1 DLL assembly

intermediaries:

  • 1 XML assembly metadata file generated based on the DLL assembly
  • 1 XML test script based on the XML test data file, which is itself validated by the XML schema file

output: I assume that you will generat a test script based on the assembly metadata and the test data to drive automatic unit testing.

http://feelite.com/blog
Top 200 Contributor
Posts 9

input:

  • 1 XML schema file
  • 1 XML test data file
  • 1 DLL assembly

intermediaries:

  • 1 XML assembly metadata file generated based on the DLL assembly
  • 1 test class generated for unit testing

The test class is the final end product that I wish to achieve.

The XML test data file had to check againist XML assembly metadata file for the various class name, methods and properties for the same variable name. If found to be true, it would get the information from the XML assembly to write out the test class for the object, and insert data from the XML test data file to create the object. Test script wise, I had to include in my codes for the various type of tests to conduct.

Thanks for your help. I hope this infomation is much clearer now.

Bonjour.

Top 25 Contributor
Posts 154

ok, it's much clearer now. Angel [A]

I deduce that the main problem here is that the XML test data which contains a list of methods signatures to relevant to testing (as well as the data used for these testing) can only be read serially using XmlTextReader. So as the other XmlTextReader iterates through the assembly metadata, you will have to search through the entire test data file every time, making the process inefficient.

How about storing the list of method of interest from the test data file into a.... list<TestInfo>? So as you iterate through the metadata, you only need to search throught this list, perhaps already sorted on the lexicographic order of the method names. (You can even serialize this list offline instead of the test data file, if efficiency is very important)

Suppose there are K methods in the assembly and you are interested in testing N methods. The run time complexity would be O(K * lg N), as compared to the O(K * N) if you read the xml test data repeatedly, not to mention the repeated object creation and collection.

http://feelite.com/blog
Page 1 of 1 (9 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems