SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML document must have a top level element.

    I am getting this error when transforming an xml document using an xsl. I have tested that the xsl works in xmlSPY and everything works fine. Both my original xml and the output xml have top level elements (can these have attributes?).

    My asp code is:

    Code:
    Set xmlDoc=Server.CreateObject("MSXML2.DOMDocument")
    xmlDoc.async=false  
    xmlDoc.load(Server.MapPath("/npt/xml/data_allcrime.xml"))
    
    
    set xslDoc = Server.CreateObject("Msxml2.FreeThreadedDOMDocument")    
    xslDoc.async = false
    xslDoc.load(Server.MapPath("/npt/xml/data_allcrime.xsl"))
    
    
    set xslTemplate = Server.CreateObject("Msxml2.XSLTemplate")  
    ' Setting the actual XSL document in the template
    xslTemplate.stylesheet = xslDoc
    ' Compile your stylesheet into a processor
    set xslProc = xslTemplate.createProcessor()
    	
    xslProc.addParameter "div", "E" 
    
    xslProc.input = xmlDoc  ' The xml input here is actually the xml you want to transform
    xslProc.transform()  ' Do the transformation
    Any help please?

    monkey
    monkey - the rest is history

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2005
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What error?

  3. #3
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry - the thread title:

    XML document must have a top level element.
    monkey - the rest is history

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2005
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you show the XML file?

  5. #5
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If i do:

    Code:
    Set xmlDoc=Server.CreateObject("MSXML2.DOMDocument")
    xmlDoc.async=false  
    xmlDoc.load(Server.MapPath("/npt/xml/data_allcrime.xml"))
    
    Set xslDoc=Server.CreateObject("MSXML2.DOMDocument")    
    xslDoc.async = false
    xslDoc.load(Server.MapPath("/npt/xml/data_allcrime_v2.xsl"))
    
    str = xmlDoc.transformNode(xslDoc)
    Response.Write(str)
    everything works fine, but i need to pass some params to the xsl.

    The xml starts:

    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    		<perfStats upToMonth="Jul" financialYear="2006-07">
    			<Division id="E">
    				<stat type="1">
                                           <YearToDateFigures>
    						<reported>111</reported>
    						<detected>45</detected>
    					</YearToDateFigures
    monkey - the rest is history

  6. #6
    SitePoint Zealot
    Join Date
    Oct 2005
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by boxhead View Post
    If i do:
    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    		<perfStats upToMonth="Jul" financialYear="2006-07">
    			<Division id="E">
    				<stat type="1">
                                           <YearToDateFigures>
    						<reported>111</reported>
    						<detected>45</detected>
    					</YearToDateFigures

    SO is it litterally asking you to add <coolStats> above your perfStats element?

    Sounds like it to me, with no attributes or anything, along with an equally closed </coolStats>

  7. #7
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by danjojo View Post
    SO is it litterally asking you to add <coolStats> above your perfStats element?

    Sounds like it to me, with no attributes or anything, along with an equally closed </coolStats>

    perfStats is my root element! Root elements can have atrtributes, but must have no siblings - which it doesn't.
    monkey - the rest is history

  8. #8
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorted it - what a fool!!!!!!!!!!!!!1

    I forgot to response.write my transform output!! hence no top level element!!

    cheers for your help
    monkey - the rest is history


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •