Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9020091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:55:44+00:00 2026-06-16T04:55:44+00:00

I have some trouble creating my XmlDocument class. This is what I’ve tried to

  • 0

I have some trouble creating my XmlDocument class. This is what I’ve tried to do:

Dim myDoc = New XmlDocument()

Dim docType As XmlDocumentType = myDoc.CreateDocumentType("DtdAttribute", Nothing, "DtdFile.dtd", Nothing)
myDoc.XmlResolver = Nothing
myDoc.AppendChild(docType)

Dim xmldecl As XmlDeclaration = myDoc.CreateXmlDeclaration("1.0", Encoding.GetEncoding("ISO-8859-15").BodyName, "yes")

Dim root As XmlElement = myDoc.CreateElement("RootElement")

myDoc.AppendChild(root)
myDoc.InsertBefore(xmldecl, root)

This will result in error: Cannot insert the node in the specified location. Line throwing this error is myDoc.InsertBefore(xmldecl, root)

Just cannot figure out this. Which order should I insert these elements? I’ve tried different orders but I think I’m just doing something totally wrong and this shouldn’t even work in the first place 🙂 But then how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:55:46+00:00Added an answer on June 16, 2026 at 4:55 am

    This works for me:

    Dim myDoc As New XmlDocument()
    Dim xmldecl As XmlDeclaration = myDoc.CreateXmlDeclaration("1.0", Encoding.GetEncoding("ISO-8859-15").BodyName, "yes")
    myDoc.AppendChild(xmldecl)
    Dim docType As XmlDocumentType = myDoc.CreateDocumentType("DtdAttribute", Nothing, "DtdFile.dtd", Nothing)
    myDoc.XmlResolver = Nothing
    myDoc.AppendChild(docType)
    Dim root As XmlElement = myDoc.CreateElement("DtdAttribute")
    myDoc.AppendChild(root)
    

    Note that the root element name must be the same as the name parameter given to XmlDocument.CreateDocumentType.

    You may find, however, that for building an XML document from scratch like this, it’s easier to just use the XmlTextWriter:

    Using writer As New XmlTextWriter("C:\Test.xml", Encoding.GetEncoding("ISO-8859-15"))
        writer.WriteStartDocument()
        writer.WriteDocType("DtdAttribute", Nothing, "DtdFile.dtd", Nothing)
        writer.WriteStartElement("DtdAttribute")
        writer.WriteEndElement()
        writer.WriteEndDocument()
    End Using
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some trouble with creating an object in an entity class. I get
I am mlearning javascript and have some trouble creating an onject via prototype. I
I am having some trouble creating a seamless photo grid. I have searched the
i seem to have some trouble installing autopy.h https://github.com/msanders/autopy/#introduction i already tried the installation
I'm having some trouble figuring out the best/Djangoic way to do this. I'm creating
I have some trouble with creating window application using PyQt. For example: we have
I'm having some trouble creating an object in C++. I create a class called
I have quite some trouble creating a WCF service that supports downloads of very
I'm creating an asteroids game and in my main class I'm having some trouble
I am creating a KeyValuePair class, and am running into some trouble when overloading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.