SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Jun 2004
    Location
    UK
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Create XML Parser object

    Hi

    I'm trying create an MSXML object so I can load an XML file into it and start to retrieve values from it. The msxml.dll is there and registered. When I try and run the code below either the object doesn't get created or it cannot load the XML file. And I just can't see why.

    Does anyone have any ideas.

    <%
    'Create an instance of MSXML to retrieve values from the XML file
    set objXML = Server.CreateObject("microsoft.xmldom")

    strPath = server.MapPath("books.xml")

    'load the XML document that we want to add to the database
    objXML.load(strPath)

    'see if the object loaded OK
    if objXML.parseError.errorCode <> 0 then
    Response.Write "object could not open"
    else
    Response.Write "object opened fine"
    end if

    set objXML = nothing
    %>

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    california, usa
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML file loading

    Hi, bloke851:

    Try adding a statement (see below) to make sure that
    the file is loaded before proceeding. (the .async property
    is defaulted to be true -- meaning that ASP will continue
    without waiting for the XML file to finish loading.)

    Code:
    ...
    'load the XML document that we want to add to the database
    objXML.async = false   ' *** to make sure the file is loaded before proceed
    objXML.load(strPath)
    ...
    cheeres,
    Andrew

  3. #3
    SitePoint Member
    Join Date
    Jun 2004
    Location
    UK
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That a good idea but I've just tried it an it no effect the parseError is still generating the same error but thanks anyway.

  4. #4
    Learning...
    Join Date
    Jan 2003
    Posts
    778
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  5. #5
    SitePoint Member
    Join Date
    Jun 2004
    Location
    UK
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi tahirjadoon

    Thanks for the reply I had a look at the above post, but I think the problem is occurring either when the objXML object is being created or when the XML file is loading because the Parse error code is always -1072896682 which is clearly not 0

    Is there some way i can find out which problem it is.

  6. #6
    Learning...
    Join Date
    Jan 2003
    Posts
    778
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you trying to load physical file or like in my case my XML doc was coming from the recordset?
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  7. #7
    SitePoint Member
    Join Date
    Jun 2004
    Location
    UK
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to load a physical file called books.xml it saved in the same directory as the asp page. I am mapping to it's physical location using

    server.MapPath("books.xml")

    Which is returning the correct path when i view it.

  8. #8
    Learning...
    Join Date
    Jan 2003
    Posts
    778
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    set objXML = Server.CreateObject("microsoft.xmldom")
    objXML.async = false
    strPath = server.MapPath("books.xml")
    'load the XML document that we want to add to the database
    objXML.load(strPath)

    Uptill here your code is fine. Instead of error number try looking at the error text by doing following:

    objXML.parseError.reason

    This might give clear picture of what is happening.

    I am doing some searching, if I find any thing will post it.
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  9. #9
    SitePoint Member
    Join Date
    Jun 2004
    Location
    UK
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks that has given me more information the error reason is

    Invalid at the top level of the document

    So it may have something to do with my XML file which is really very simple

    <?xml version="1.0" standalone="no"?>
    <books>
    <book>
    <title>Beginning ASP 3.0</title>
    <ISBN>1-861003-38-2</ISBN>
    <authors>
    <author_name>Brian Francis</author_name>
    <author_name>Chris Ullman</author_name>
    <author_name>Dave Sussman</author_name>
    <author_name>John Kauffman</author_name>
    <author_name>Jon Duckett</author_name>
    <author_name>Juan llibre</author_name>
    </authors>
    <description>
    ASP is a powerful technology for dynamically creating website content.
    Learn to create exciting pages that are tailored to your audience.
    Enhance your web/intranet presence with powerful web applications.
    </description>
    <price US="$49.99"/>
    <rating>Very good as learning material not so good as a reference book</rating>
    </book>
    </books>

  10. #10
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    california, usa
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, Bloke851:

    I have used your original asp code as well as books.xml in my machine: it works!
    So, I think the problem probably in the ASP configuration.
    Also: I used following statements to test different versions of MSXML in my machine:
    Code:
    ' set objXML = Server.CreateObject("MSXML2.DOMDocument")     ' yes
    ' set objXML = Server.CreateObject("MSXML2.DOMDocument.2.6") ' no
    ' set objXML = Server.CreateObject("MSXML2.DOMDocument.3.0") ' yes
    set objXML = Server.CreateObject("MSXML2.DOMDocument.4.0")  'yes
    ' set objXML = Server.CreateObject("Microsoft.XMLDOM")          'yes
    Note: from MSDN-newsgroup site, some guru strongly advises NOT to use
    "Microsoft.XMLDOM", I think this is probably the older version. Anyway,
    the above statements 'yes means works in my machine. 'no means not.
    Cheers,
    Andrew

  11. #11
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    california, usa
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    I found this article at MSDN-site.
    It has the code to walk through XML nodes and attributes.

    http://msdn.microsoft.com/library/de...tarter_kit.asp

    Hope this helps.

    Cheers,
    Andrew


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
  •