Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie - DataSet.ReadXml Error 2

Status
Not open for further replies.

bppj

Programmer
Jun 6, 2002
24
US
I'm pretty new to all this XML and .net stuff... not sure if this question belongs here or in the XML forum.

I'm writing a VB.NET program to take data provided by our IT department from our Unix/universe "mainframe" system and update our tables in a MSDE enviroment for ASP.NET use. Anyway, I was originally thought I was going to have to parse a txt file, but they decided to give it to me in XML... all the better, so I thought.

Anyway, I used:

DataSet1.ReadXml("filename.xml")
to generate a dataset to use to update the database. Problem is, when the program runs and tries to inturpret the xml, I get the following error:

'xml:stylesheet' is an invalid name for a processing instruction. Line 2, posistion 3.

I look at a demo file (more on trying to edit the original file later):

<?xml version=&quot;1.0&quot;?>
<?xml:stylesheet type=&quot;text/xsl&quot; href=&quot;WEBXML.xsl&quot;?>
<WEBP>
<ITEM>
<SER>AKCU01072</SER>
<PART>P70680</PART>
</ITEM>

... more elements...

Anyway, as I said, I'm new to this xml stuff, but I did go looking for examples of properly formatted xml, and found if I change the second line to:

<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;WEBXML.xsl&quot;?>

everything works hunky-dory. In fact, I have the program working... it humms along and updates my msde database.

I asked the IT guy who gave me the xml how it was generated. He knows about as much about xml as I do. He said he just used a &quot;save as&quot; feature in his wintegrate program.

Now, the problem is, I don't want to have to make this change everytime I receive new data. And to make troubles worse, the inital dump file for the database we are working on seems to be too big for me to open directly and change this second line. (run out of storage error).

SO! Any ideas on:
1. Why I am getting &quot;badly formatted&quot; xml in the first place? Or is it a .net parsing problem?
2. How to ignore this process instruction completely so I can use the xml in my program without bombing out?
3. Other ideas???

Thanks in advance for the help.




 
in fact you can find some differences among all XML files. .NET seems to have its own format for SOAP for example (that is only an other xml format).

I recommand you to add an app.config where you place for example all &quot;wrong&quot; lines, and the correct line.
Before to make a .ReadXml, you simply have to replace (thanks to your code, not manually) the bad string.
Each time you find a new wrong string format, you add it into your app.config. I don't think you will find more than 2 or 3 different format for the tag <?xml-stylesheet>

By the way, i don't think you have a lot of things to do, if wintegrate saves in a wrong format... Then try to know if you can select a specific format before to save into XML.

hope it helps
Best regards,
Elise, XML learning girl X-)
 
Thank you very much for answering, Elise!

Remember, I am a real &quot;newbie&quot; to all this stuff, so I just want to make sure that I am going down the right path:

1. My program will need to read the XML file and find the &quot;incorrect&quot; string as defined in my app.config file.
2. The code will then need to replace this string with my &quot;correct&quot; data as defined in my app.config.
3. Save the XML file, then let my program proceed to loading the data into my dataset as already written.
4. If necessary, I can use my dynamic properties capablility in my app.config file to add other &quot;incorrect&quot; strings if they are discovered.

I just wanted to make sure there wasn't some &quot;easier&quot; way to make the xml changes on the fly that I wasn't aware of!

Again, thanks in advance for the help!!! Any other pointers will obviously be appreciated.

Best regards,

B.J.
 
yes that's correct, that's the only solution i see. Maybe someone else knows an other one.

Best regards,
Elise, XML learning girl X-)
 
One option might be to utilize the StreamReader/Streamwriter object to replace the string prior to trying to read them into a dataset. For instance:

Dim sXML As String
Dim srReader As System.IO.StreamReader = New System.IO.StreamReader(&quot;C:\filename&quot;, False)
Dim srWriter As System.IO.StreamWriter = New System.IO.StreamWriter(&quot;c:\filename_to_save&quot;, False)

sXML= srReader.ReadToEnd
sXML = replace(sXML, &quot;xml:stylesheet type&quot;, &quot;xml-stylesheet type&quot;)

srWriter.Write(sXML)
'or maybe srWriter.Writeline(sXML), I use it differently so am not 100% sure
srWriter.Close()

Then read in the filename_to_save file into your dataset.

O.




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top