Author Topic: External Data Storage with XML and VLISP  (Read 35406 times)

0 Members and 1 Guest are viewing this topic.

Columbia

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #45 on: May 15, 2008, 01:06:54 PM »
Okay then, copy and paste the source code that I posted earlier in this thread.  Find the line that says "MSXML2.DOMDocument.3.0" and change it to "MSXML2.DOMDocument.6.0".  Load the source code, and the rerun original sample code.

psuchewinner

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #46 on: May 15, 2008, 01:50:41 PM »
when I changed it to "6" I got this error:
 error: bad argument type: VLA-OBJECT nil

When I changed it back to "3", I got a VLA-OBJECT but got nil for the variable "sRegenValue" on the next statement

Columbia

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #47 on: May 15, 2008, 02:02:45 PM »
Try 4 & 5 as well as 3 & 6.  I'm thinking it may be a problem with the MSXML DOM api that you have installed on your PC.

psuchewinner

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #48 on: May 15, 2008, 03:09:09 PM »
No Go there.  I get the same result...the nil...with 3, 4 & 5.  6 doesn't work at all.

Atleast I have found a challenging problem.... :evil:

psuchewinner

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #49 on: May 19, 2008, 08:33:24 AM »
Ok,
I Got it !!!!!!!!! :lol:
Yehaw.
Turns out that the problem was with the XML File.  I used the XML Notepad.
Now on to bigger and better things.

Thanks for the help and sorry for the aggravation.

Columbia

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #50 on: May 19, 2008, 09:22:39 AM »
What was wrong in the XML file?  I want to make sure that the sample I gave everybody else is going to be kosher.

psuchewinner

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #51 on: May 19, 2008, 04:29:05 PM »
I am not sure what was wrong really.  I originally copied it fomr this post and pasted it into a word file and renamed it as an XML file.  When I realized that was not good, I pasted it into the MS XML Notepad and it still did not work right.  This morning I started it from scratch in XML notepad and it worked.   :-D

Nothing like leaning something new.  Guess I will dig into this XML thing next.  I areally appreciate your help and patience.

lispman21

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #52 on: May 20, 2008, 01:20:50 PM »
I am having a little trouble myself using this API and i am sure it is just because i don't understand what i am doing.  I have an XML file and for testing purposes i want to get the Value of the Object Result_Value in the xml file when the Engine_Code attribute is CC04/BL01 if the Result_field object.

Here is my stab at it but it is not working at all.  I have also attached the xml file.  If you could explain what i am doing wrong it would be greatly appreciated.  I could only attache txt files so you will have to change the file xtension to xml.

Source Code:
Code: [Select]
(vl-load-com)
(load "xml-api.vlx")
(setq oSettings (XML-Get-XMLObject "C:\\RTU-2.xml"))
(setq enginecode
       (read
(XML-Get-Attribute
  (xml-Get-Child-ByAttribute oSettings "Result_Field" "Type" "value")"Engine_Code" "CC04/BL01")
)
      )
(if (= enginecode "CC04/BL01")
  (setq oResultValue (xml-Get-Child-Value oSettings "Result_Value" "Value"))
  )

Columbia

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #53 on: May 20, 2008, 02:26:25 PM »
Okay let's see if we can break this down to a more manageable level...

Code: [Select]
;; Starting the VLIDE runtime module
(vl-load-com)

;; Loads the XML-API.vlx
(load "xml-api.vlx")

;; gets a node object corresponding to the 'Job' level of the XML file.
(setq oSettings (XML-Get-XMLObject ("C:\\RTU-2.xml")))

I'm guessing that after this is where you're running into your wall...
And if I'm guessing correctly then what you want to accomplish is actually what's listed below.

Code: [Select]
;; get down to the Unit node by going through the Product node.
(setq nUnit (XML-Get-Child oSettings "Product" "Unit"))

;; Once we have the Unit node then we can look for the Correct Module, like so...
;; We'll use the Module whose Name is Unit Level for ease of explanation
(setq nModule (XML-Get-Child-ByAttribute nUnit nil "Name" "Unit Level"))

;; Now that that is done, we're going to reach out for the Result Parent Node
(setq nResult (XML-Get-Child nModule "Criteria" "Result"))

;; Okay now we're getting down to the nitty gritty - we're almost there.
;; So now we'll look through the rest of the child nodes, find the one with the correct Result_Field type and
;; then return the Engine_Code value from there.
(setq sVal (XML-Get-Attribute (XML-Get-Child-ByAttribute nResult nil "Type" "value") "Engine_Code" "CC04/BL01"))

;; We set the default value to "CC04/BL01" so at the very least we should get that. 
(if (= sVal "CC04/BL01")
  (progn
    ;; ... keep on coding from here
  )
)

;; And don't forget to release your objects...
(mapcar 'vlax-release-object (list nResult nModule nUnit oSettings))


Hope this Helps!

P.S.
Keep in mind that I didn't debug this or test it.  I just wrote as I went along.  Acutally if there are no bugs, then I would be most surprised.  However, the whole point of the post was to try to lay out how to use the API.  The biggest error I found with the snippet you posted, was that it wasn't going down far enough into the XML nested structure.  - Cheers!

lispman21

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #54 on: May 20, 2008, 02:50:34 PM »
This helps and explains a whole lot to me.  I also appreciate your quick response and depth of detail in your explanations.  This should come in very handy in the near future for me.

lispman21

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #55 on: May 20, 2008, 03:48:37 PM »
I know you said you hadn't debugged or tested the code you posted.  I have been looking at it and  below is what i have but the nModule variable returns a value of nil which is messing up the program.  I can't figure out why is it a problem with the xml or the way i have my argument written.  Thanks in advance.

Code: [Select]
;; Starting the VLIDE runtime module
(vl-load-com)

;; Loads the XML-API.vlx
(load "xml Application.lsp")

;; gets a node object corresponding to the 'Job' level of the XML file.
(setq oSettings (XML-Get-XMLObject "C:\\RTU-2.xml"))
;; get down to the Unit node by going through the Product node.
(setq nUnit (XML-Get-Child oSettings "Product" "Unit"))

;; Once we have the Unit node then we can look for the Correct Module, like so...
;; We'll use the Module whose Name is Unit Level for ease of explanation
(setq nModule (XML-Get-Child-ByAttribute nUnit "Unit" "Name" "Unit Level"));; Value returned as nil for some reason

;; Now that that is done, we're going to reach out for the Result Parent Node
(setq nResult (XML-Get-Child nModule "Criteria" "Result"))

;; Okay now we're getting down to the nitty gritty - we're almost there.
;; So now we'll look through the rest of the child nodes, find the one with the correct Result_Field type and
;; then return the Engine_Code value from there.
(setq sVal (XML-Get-Attribute (XML-Get-Child-ByAttribute nResult nil "Type" "value") "Engine_Code" "CC04/BL01"))

;; We set the default value to "CC04/BL01" so at the very least we should get that. 
(if (= sVal "CC04/BL01")
  (progn
   (alert "YEAH") ;; ... keep on coding from here
  )
)

;; And don't forget to release your objects...
(mapcar 'vlax-release-object (list nResult nModule nUnit oSettings))

Columbia

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #56 on: May 20, 2008, 04:01:08 PM »
One thing to be very aware of is that XML file values for attributes and nodes are case sensitive.  And I fell victim to that in my example to you.  I put in to search for "Unit Level" when I should have had "Unit level".  Not much difference to most people, but to the computer it's huge.  Try that out.

lispman21

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #57 on: May 21, 2008, 07:49:00 AM »
That seemed to be the problem.  Thanks for your help.

lispman21

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #58 on: May 22, 2008, 02:36:24 PM »
It's me again.  I am starting to understand this a little more and more the longer i fool with it.  I am kind of stuck now though.  I am trying to get to the unit node when the Unit name is one from a list i have constructed in the code below.  The variable nUnit keeps returning nil when it tries to go into the unit node through where agian the unit name is one from a list.  This list of names was constructed by getting the child list under the product node and then using xml-get-attribute to return the name for each child under the product node.  There could be multiple Unit nodes per XML file so i am wanting to make the program run for each unit.  I hope I have made some since of what i am trying to do and what is wrong it just seems hard for me to explain it.  Attached is an xml file with multiple Unit nodes.

Source Code:
Code: [Select]
;;;****************************************************************************************************
;;; XML.lsp                                                                                           *
;;; Prepared by: J. Preston                                                                           *
;;; Date: 21 May 2008                                                                                 *
;;; Purpose: To provide a Program to read an XML file and draw the CAD drawings less their dimensions.*
;;; Copyright (c) 2008 - All rights reserved                                                          *
;;;****************************************************************************************************
;;; Version 2008.05.21                                                                                *
;;;****************************************************************************************************

;;;******************************************************************************
;;; MODULE: C:XML                                                               *
;;; DESCRIPTION: Searches for Unit Module information in user selected XML file *
;;; DESCRIPTION: function returns a CAD Drawing of the needed Air Handling Unit.*
;;;******************************************************************************

(defun C:xml ()
;; Starting the VLIDE runtime module
(vl-load-com)

;; Loads the XML-API.vlx
(load "xml Application.lsp")
;;(load "CV AHU.LSP")

;; gets a node object corresponding to the 'Job' level of the XML file.
(setq oSettings (XML-Get-XMLObject (getfiled "Get XML File" "C:\\" "XML" 2)))
;; get down to the Product node.
(setq UName (XML-Get-Child oSettings nil "Product"))

;; get down to the Unit node by going through the Product node.
(setq nUnito (XML-Get-Child oSettings "Product" "Unit"))
 
;; Getting the list of Child nodes to use for a counting mechanism in my while statement
(setq childlist (XML-Get-Childlist nunito))
 
;;;; Getting the number of units in XML and Unit Names
;;Getting VLA-OBJECT List of names of the children under the product node 
(setq childlist2 (XML-Get-Childlist UName))
;; getting the number of children
(setq num1(Length childlist2))
;; setting counter for unit names
(setq UCount 0)
(setq UList '())
;; Process the list of children and return their Names in a list
(While (< UCount num1)
  ;; Getting the name of the first VLA-OBJECT in the child list
  (setq UNAME2 (xml-get-attribute (car childlist2) "Name" nil))
   ;; making a list of the names
   (setq UList (if UList (append UList (list UNAME2))(list UNAME2)))
   ;; removing the VLA-OBJECT that was just used
   (setq childlist2(cdr childlist2))
  ;; Increasing the counter by one
  (setq UCount (+ UCount 1))
);; End of While Statement
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq MCount 0);; initializing counter for main program
(While (< MCount num1)
 
 ;;Now were specifying our selection to be the Unit with the Name from the child list
(setq nunitname (XML-Get-Child-ByAttribute UName nil "Name" (car UList)))
 
 ;;get down to the Unit node where the unit name is the one from the list
(setq nUnit (XML-Get-Child nunitname nil "Unit"))
 
;; Now were specifying our selection to be the Module with the Name Unit Level
(setq nunitlevel (XML-Get-Child-ByAttribute nUnit nil "Name" "Unit level"))
 
;; Now we're stepping down into the node "Result"
(setq nUnit1 (XML-Get-Child nunitlevel "Criteria" "Result"))
 
;; Specifying our search for the result_value we want in this case the FCAT which is UBAS
(setq ULBase (XML-Get-Child-ByAttribute nUnit1 nil "FCAT" "UBAS"))
 
;; Stepping down into the nod Result_Value
(setq ULBase2 (XML-Get-Child ULBase nil "Result_Value"))
 
;;Getting the Value of FCODE from the Result_Value node under FCAT UBAS
(setq ULBase3 (xml-get-attribute ULBase2 "FCODE" nil))
 
;; Detailing what the "Base Height" value should be depending on the value returned.
(if (= ULBase3 "BR06")
  (setq BHT 6.0)
(if (= ULBase3 "BR08")
  (setq BHT 8.0)
(if (= ULBase3 "BR10")
  (setq BHT 10.0)
)))
;; getting the amount of items in the list and subtracting 2 for unit level and controls package
(setq num (-(length childlist)1))
  (setq count 1);; initializing counter
      (setq len 0);; resetting the values
      (setq len2 '());; resetting the List

;; Starting while statement to retrieve Unit Size information.  The counter is set so that length values for the modules
;; will be returned.  If i need to see the values returned i compiled them into a list under the variable len2
  (While (< count num)
    (setq count1 (rtos Count 2 0));; setting the counter interger to a string

;; Once we have the Unit node then we can look for the Correct Module, like so...
;; We'll use the Module whose Module_Number is 1 (using a counter for the actual number) for ease of explanation
     (setq nModule (XML-Get-Child-ByAttribute nUnito nil "Module_Number" Count1))
;; getting the Length value of the Current module   
      (setq sval4 (xml-get-attribute nModule "Length" nil))
;; converting the value of Length into a real number   
       (setq svalatof (atof sval4))
;; Adding all the length of the modules together
        (setq len (if len (+ len svalatof)(+ svalatof 0)))
;; Compiling a list of all the lengths that were returned for each module number
        (setq len2 (if len2 (cons len2 svalatof)(list svalatof)))
;; stepping the counter up by 1
    (setq count (+ count 1))
 );; end of while
 
;; Now that that is done, we're going to reach out for the Result Parent Node
;(setq nResult (XML-Get-Child nModule "Criteria" "Result"))
  (setq HT (Atof(xml-get-attribute nModule "Height" nil)));; getting the Height value of the Unit
  (setq wdth (Atof(xml-get-attribute nModule "Width" nil)));; getting the Width value of the Unit
  ;;(c:CV2 HT len wdth BHT);; calling the program that draws the unit skeleton and passing 4 variables to it

  (setq Ulist (cdr Ulist))
  (setq MCount (+ MCount 1))
 );; end of Big While
 
;; Okay now we're getting down to the nitty gritty - we're almost there.
;; So now we'll look through the rest of the child nodes, find the one with the correct Result_Field type and
;; then return the Engine_Code value from there.
;(setq sVal  (XML-Get-Child-ByAttribute nResult nil "FCAT" "OPG2"))
;(setq nResult2 (XML-Get-Child sval nil "Feature"));; stepping down to the Feature node when Result_Field node attribute FCAT has a value of OPG2
;(setq sval2 (xml-get-attribute nResult2 "SizeY" nil));; Getting the value of the attribute "SizeY" in the Feature node
;(setq svalatof (atoi sval4));; converting the value of SizeY into a real number
;;;   (setq mypnt (getpoint))
;;;   (setq line1 (polar mypnt (dtr 0)len))
;;;   (command "line" mypnt line1 "")
;; We set the default value to "CC04/BL01" so at the very least we should get that. 
;;;(if (/= sVal4 "")
;;;  (progn
;;;   ;; ... keep on coding from here
;;;   (setq line1 (polar mypnt (dtr 0)svalatof))
;;;   (command "line" mypnt line1 "")
;;;  )
;;;)

;; And don't forget to release your objects...
(mapcar 'vlax-release-object (list nModule nUnit nUnito oSettings nUnitlevel nUnit1 ULBase ULBase2 UName nUnitname))
)

lispman21

  • Guest
Re: External Data Storage with XML and VLISP
« Reply #59 on: May 23, 2008, 08:28:42 AM »
Ok, I beleive i figured out my problem i posted previous to this post.  I was already in the unit node so therefore i couldn't find it when i was trying to call it.