Results 1 to 5 of 5

Thread: XML Newbie question

  1. #1

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    XML Newbie question

    I have a simple XML format

    <Block>
    <Block_Title></Block_Title>
    <BlockCode></BlockCode>
    <PreProcess></PreProcess>
    </Block>
    <Config></Config>

    Which I have had to wrap with <root></root> but other than that it's basic and does the job

    Now here is the code that will deal with the contents.

    Module_Name and Block_Name are used to build the file and path relative to the function (that's the job of another bit of code).


    [vbscript]
    <%
    Function DoBlockPut(Module_Name, Block_Name)

    Dim mydoc, objLst

    Set mydoc=Server.CreateObject("Microsoft.XMLDOM")
    Set objLst = Server.CreateObject("Microsoft.XMLDOM")

    mydoc.async=false

    mydoc.load(Server.MapPath(Module_Name & "\Blocks\" & Block_Name & ".block"))

    'Debugging
    Response.Write Server.MapPath(Module_Name & "\Blocks\" & Block_Name & ".block") & "<br />"

    if mydoc.parseError.errorcode<>0 then
    Response.write "Error with Block_XML (" & mydoc.parseError.errorcode & ") with " & Module_name & " - " & Block_Name & "<br />"
    else
    ' proceed
    Set objLst = mydoc.getElementsByTagName("Block")

    dim title, code, btype

    Set title = mydoc.getNamedItem("Block_Title")
    Set code = mydoc.getNamedItem("BlockCode")
    Set btype = mydoc.getNamedItem("PreProcess")

    'Call StartBox(title)

    if btype = 0 then
    server.execute(code)
    Else
    response.write(code)
    end if

    'Call EndBox

    end if

    end function
    %>
    [/vbscript]

    however it seems I can do no right with this section

    Set objLst = mydoc.getElementsByTagName("Block")

    dim title, code, btype

    Set title = mydoc.getNamedItem("Block_Title")
    Set code = mydoc.getNamedItem("BlockCode")
    Set btype = mydoc.getNamedItem("PreProcess")

    which has now come to look a little silly as it has not worked no matter what I have done.

    I have to admit I have no idea what I am doing. with this XML stuff for the main part and when it comes to MSXML ...foobar bar bar foo ...I have no idea.
    ?
    'What's this bit for anyway?
    For Jono

  2. #2

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    Hello? Help...
    ?
    'What's this bit for anyway?
    For Jono

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Your method of traversal of the tree is completely wrong. You want to call getNamedItem on objLst, not myDoc. Even so, the calls will fail. Read carefully through the documentation of the methods you use and find out what they really do.

    Also, this line is completely useless:
    Set objLst = Server.CreateObject("Microsoft.XMLDOM")
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    so I am starting to learn...

    and wow I compleatly failed to ask any actual question(s)...

    I need a holiday - XML is too tricky.

    Why does every introductory guide talk at length about the history of XML and then in great detail about the format of XML and sometimes the use of XML and then end with a few snippits of code that are no earthly use at all?

    is it too much to ask for a simple demo script in PHP. ASP or french for all it matters, that loads a file and then doesn't do a lot more than load it.

    Maybe an example of save and one of add node...

    Any takers?
    ?
    'What's this bit for anyway?
    For Jono

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Why does every introductory guide talk at length about the history of XML and then in great detail about the format of XML and sometimes the use of XML and then end with a few snippits of code that are no earthly use at all?
    Because the tutorials you view are probably about XML itself - what it is for, what it looks like etc. Not about how to make use of it within programming languages. But every XML tutorial probably mentions DOM and SAX, the two main methods of using XML. So look for DOM and SAX tutorials in your language of choice.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width