Just a little thing bugging me
Just a little thing bugging me
Just a little thing bugging me
Just a little thing bugging me
Just a little thing bugging me
Just a little thing bugging me Just a little thing bugging me Just a little thing bugging me Just a little thing bugging me Just a little thing bugging me Just a little thing bugging me Just a little thing bugging me Just a little thing bugging me
Just a little thing bugging me Just a little thing bugging me
Just a little thing bugging me
Go Back  Xtreme Visual Basic Talk > > > Just a little thing bugging me


Reply
 
Thread Tools Display Modes
  #1  
Old 11-24-2014, 03:51 PM
VisualaBasikka VisualaBasikka is offline
Centurion
 
Join Date: Oct 2004
Posts: 130
Default Just a little thing bugging me


I have a .xml data file which will be read by my vb.net program

Code:
   doc = New XmlDocument
            doc.Load("myfile.xml") 'This file must be in the bin folder of the program.
If my .xml file doesn't include a DTD declaration it's fine, but if it does (see below) I get an error that says "XML exception unhandled. Invalid text declaration. Line 1, position 22."

Quote:
<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE UserPlayLists SYSTEM "myfile.DTD">
Does this mean I can't use VB.net to load an .xml which has a DTD declaration? Or am I doing something wrong?
Reply With Quote
  #2  
Old 11-24-2014, 04:25 PM
PlausiblyDamp's Avatar
PlausiblyDampJust a little thing bugging me PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

IIRC you can tell an XmlDocument to ignore DTDs by setting the XmlResolver property (http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx) to Nothing.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 11-25-2014, 02:00 PM
VisualaBasikka VisualaBasikka is offline
Centurion
 
Join Date: Oct 2004
Posts: 130
Default

Still returns the same error, I have changed the code to this:

Code:
    Public Function GetDoc() As XmlDocument
        If doc Is Nothing Then
            MessageBox.Show("doc does not exist, creating doc")
            Dim resolver As XmlUrlResolver = New XmlUrlResolver()
            resolver.Credentials = CredentialCache.DefaultCredentials

            Dim doc As XmlDocument = New XmlDocument
            doc.XmlResolver = resolver
            doc.Load("myfile.xml")
        Else
            MessageBox.Show("doc already exists")
        End If
        Return doc
    End Function
I haven't included the follwing line at the top of that linked page because it seems to give a syntax error regardless where in the project I put it
Code:
'Declaration
Public Overridable WriteOnly Property XmlResolver As XmlResolver
Reply With Quote
  #4  
Old 11-25-2014, 05:12 PM
PlausiblyDamp's Avatar
PlausiblyDampJust a little thing bugging me PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Just tried it with a sample XML document here and
Code:
Dim doc = New XmlDocument
doc.Load("myfile.xml")
failed with an exception while trying to load the DTD, however
Code:
Dim doc = New XmlDocument
doc.XmlResolver = Nothing
doc.Load("myfile.xml")
loaded the document just fine.

I notice in your original question though the error was
Quote:
XML exception unhandled. Invalid text declaration. Line 1, position 22.
which indicates a problem with the XML rather than a missing DTD. Is the DTD present and if so is the XML itself correct based on the rules of the associated DTD?
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #5  
Old 11-25-2014, 06:46 PM
VisualaBasikka VisualaBasikka is offline
Centurion
 
Join Date: Oct 2004
Posts: 130
Default

The xml file is well-formed and validated. Changing it to

Code:
doc.XmlResolver = Nothing
removed the error only for another to crop up.

The next code is trying to show the xml in a messagebox, I get a "nullreferenceexception was unhandled" error which I think means the xml hasn't loaded at all. I tried again with the DTD dec removed from the xml file and the code worked perfect.

Code:
        Dim allText As String = doc.InnerText
        MessageBox.Show(allText)
Reply With Quote
  #6  
Old 11-26-2014, 12:51 AM
Cerian Knight's Avatar
Cerian KnightJust a little thing bugging me Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

(After 15 minutes of research on a subject I'm not very familiar with) here is a link containing a full example of a Private External DTD (using 'standalone="no"' as a rule):
http://xmlwriter.net/xml_guide/docty...laration.shtml
If 'standalone' does not work, see if you can get the External example to work as written. If so, change it one step at a time, substituting your XML declaration, etc.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').

Last edited by Cerian Knight; 11-26-2014 at 01:01 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Just a little thing bugging me
Just a little thing bugging me
Just a little thing bugging me Just a little thing bugging me
Just a little thing bugging me
Just a little thing bugging me
Just a little thing bugging me Just a little thing bugging me Just a little thing bugging me Just a little thing bugging me Just a little thing bugging me Just a little thing bugging me Just a little thing bugging me
Just a little thing bugging me
Just a little thing bugging me
 
Just a little thing bugging me
Just a little thing bugging me
 
-->