Click here to Skip to main content
14,384,332 members

How do I sort an XML file

Dave the Golfer asked:

Open original thread
I am trying to sort the data in an xml file before creating reports of the data.

My xml file is like
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE SpringOpen SYSTEM "Seniors_Open.dtd"[]>
    <Club1>Man United</Club1>

I am trying to sort the data by the element TeamNumber

my XSL file is
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
  <xsl:strip-space elements="*"/>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="SpringOpen">
      <xsl:apply-templates select="Team">
        <xsl:sort select="TeamNumber" data-type="text"/>

  <xsl:template match="@* | node()">
      <xsl:apply-templates select="@* | node()"/>


What I have tried:

My is
Dim xslt As New XslCompiledTransform()
        xslt.Load(Path & "\Spring_Open.xsl")

        ' Execute the transform and output the results to a file.
        xslt.Transform(Path & "\Spring_Open.xml", Path & "\sortedSpring_Open.xml")

The error I get when executing the transform is
System.Xml.XmlException: 'For security reasons DTD is prohibited in this XML document. To enable DTD processing set the DtdProcessing property on XmlReaderSettings to Parse and pass the settings into XmlReader.Create method.'

Being an absolute novice I do not understand what the error means!
Can anyone help to solve my problem.

I have deleted
<!DOCTYPE SpringOpen SYSTEM "Seniors_Open.dtd"[]>
from my xml file and it now works Why?


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100