Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Association List to XML? Please help.

15 REPLIES 15
Reply
Message 1 of 16
mid-awe
1102 Views, 15 Replies

Association List to XML? Please help.

Hi all,

 

I have been tinkering away at this ever since it was suggested to utilize XML for data transport and storage and then W3C went and stated "If developers DO have sense, future applications will exchange their data in XML." So, it became a priority to me and perhaps you.

 

Many of us, including me, prefer to just stick with (A/V)LISP for as long as AutoCAD will accept it. I did many loong searches for hints of LISP to XML functions finding only the xml-api.lsp and it's great for what it does.

 

Because I still need a good simple way to generate the XML file to use the xml-api I have kicked around a way to dump an association list into xml format. Namely a way to construct valid XML from a structured association list. Atoms become tags and dotted pairs become attributes + values. Nesting is intrinsic of both although terminology is different they are essentially the same.

 

The code below is my current progress with help from Lee Mack & hmsilva (thank you both for those bits & pieces). I'm not an expert, obviously 😉 but I know what I have this far is cool. My need for help here could be benefitial to anyone traveling this road or any developer whom has sense 🙂

 

Running the two test functions will reveal the situation. A top level list as with "testit1" works well (read notes), but as soon as I nest deeper, errors arise. I have an idea of what is needed but the code already has issues due to having been formed on top of a recursive function; and, I'm struggling to solve.

 

Can you help?

 

(DEFUN ASSOC->XML (l)
  (VL-LOAD-COM)
  
  (DEFUN XMLify (data / x y z) ;| hmsilva - http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Recursively-check-for-characters-and-... |;
    (SETQ x '("<" ">" "& " "'" "\"")
	  y '("&lt;" "&gt;" "&amp; " "&apos;" "&quot;")
	  z (LENGTH x)
    )
    (WHILE (NOT (MINUSP (SETQ z (1- z))))
      (WHILE (VL-STRING-SEARCH (NTH z x) data)
        (SETQ data (VL-STRING-SUBST (NTH z y) (NTH z x) data))
      )
    )
    data
  )

  (DEFUN rtn-str (val) (IF (EVAL val) (IF (= (TYPE val) 'int) (ITOA val) val)))
  
  (FOREACH i l
    (COND
      ; <- Somehow collect parents nodes for closing later 
      ((ATOM i)
       (IF (EQ i (STRCASE i))
	 (PROGN
	   (IF (AND (/= ax|p i) (NOT (NULL ax|p)))
	     (PROGN (WRITE-LINE (STRCAT " /></" ax|p "><" i) output)
		    (SETQ ax|p i ax|t nil)
	     )
	     (PROGN (SETQ ax|p i) (WRITE-LINE (STRCAT "<" i) output))
	   )
	 )
	 (IF (NULL ax|t)
	   (PROGN (WRITE-LINE (STRCAT "><" (STRCASE ax|p T) " ITEM=\"" i "\"") output) (SETQ ax|t T))
	   (PROGN (WRITE-LINE (STRCAT " /><" (STRCASE ax|p T) " ITEM=\"" i "\"") output) (SETQ ax|t nil))
	 )
       )
      )
      ((= (CDR i) nil) (ASSOC->XML (CDR i)))
      ((NOT (OR (ATOM i) (LISTP (CDR i))))
       (WRITE-LINE
	 (STRCAT (IF (VL-SYMBOLP (CAR i)) (VL-SYMBOL-NAME (CAR i)) (CAR i))
		 "=\"" (XMLify (rtn-str (CDR i))) "\""
	 ) output
       )
       (SETQ ax|t T)
      )
      ((LISTP i) (ASSOC->XML i))
    )
  )
  ; <- Somehow close parent nodes before exiting 
  (PRINC)
)

;;| Tests 1 & 2 
(DEFUN c:testit1 ()
  (SETQ	ax|p nil ax|pp nil ax|t nil)
  (ASSOC->XML
    (CDR
      '(SOFTSCAPE ("PALM" ("Pygmy Palm" (BOTANICAL . "Phoenix robelinii") (SIZE . " 15 GAL") (COLOR) (QTY . 2)))
		  ("SHRUB" ("Arizona Yellow Bells" (BOTANICAL . "Tecoma stans var. agustata") (SIZE . " 5 GAL") (COLOR) (QTY . 2))
			   ("Brave River Sage" (BOTANICAL . "Leucophyllum langmaniae") (SIZE . " 5 GAL") (COLOR) (QTY . 6))
			   ("Chuparosa" (BOTANICAL . "Justicia californica") (SIZE . " 5 GAL") (COLOR) (QTY . 4))
			   ("Pink Fairy Duster" (BOTANICAL . "Calliandra eriophylla") (SIZE . " 5 GAL") (COLOR . "PINK") (QTY . 5))
		  )
		  ("GROUNDCOVER" ("New Gold Lantana" (BOTANICAL . "Lantana hybrid 'New Gold'") (SIZE . " 5 GAL") (COLOR) (QTY . 5)))
		  ("ACCENT" ("Ocotillo" (BOTANICAL . "Fouquieria splendens") (SIZE . " bare root") (COLOR) (QTY . 1))
			    ("Toothless Desert Spoon" (BOTANICAL . "Dasylirion quadrangulatum") (SIZE . " 5 GAL") (COLOR) (QTY . 2))
		  )
		  ("CACTUS" ("Argentine Giant" (BOTANICAL . "Trichocereus candicans") (SIZE . " 5 GAL") (COLOR) (QTY . 1))
			    ("Mexican Fencepost" (BOTANICAL . "Pachycereus marginatus") (SIZE . " 5 GAL") (COLOR) (QTY . 2))
			    ("Purple Prickley Pear" (BOTANICAL . "Opuntia violacea 'Santa Rita'") (SIZE . " 5 GAL") (COLOR) (QTY . 2))
		  )
		  ("LIGHTS" ("Path" (BOTANICAL) (SIZE) (COLOR . "RUST") (QTY . 5))
			    ("Spot" (BOTANICAL) (SIZE) (COLOR . "RUST") (QTY . 5))
			    ("Transformer" (BOTANICAL) (SIZE) (COLOR) (MODEL . "300") (QTY . 1))
		  )
       )
    )
  )
  (PRINC (STRCAT " /></" ax|p ">")) ; Close parent tag 
  (if ax|pp (princ (strcat "</" ax|pp ">"))) ; Close top-level parent tag 
  (SETQ	ax|p nil ax|pp nil ax|t nil) ; empty globs 
  (PRINC)
)

(DEFUN c:testit2 ()
  (SETQ	ax|p nil ax|pp nil ax|t nil)
  (ASSOC->XML 
    '("DrawingData" (DATEDRAWN . "1/6/14") (DRAFTNAME . "Me")
	(REVISIONS ("REVISION1" (WHO . "You") (WHEN . "2/16/2014") (WHAT . "Material colors, CO# 52498"))
		   ("REVISION2" (WHO . "Another") (WHEN . "2/24/2014") (WHAT . "SQFT Adjusted"))
		   ("REVISION3" (WHO . "You") (WHEN . "2/25/2014") (WHAT . "Something else"))
		   ("REVISION4" (WHO . "Other") (WHEN . "2/26/2014") (WHAT . "Add Coping, CO# 52633"))
		   ("REVISION5" (WHO . "Another") (WHEN . "2/28/2014") (WHAT . "Add Sand color"))
		   ("REVISION6" (WHO . "Me") (WHEN . "3/2/2014") (WHAT . "Revised Per Layout"))
		   ("REVISION7" (WHO . "Other") (WHEN . "3/4/2014") (WHAT . "Change Per Super, CO# 52891"))
	)
        (SOFTSCAPE ("PALM" ("Pygmy Palm" (BOTANICAL . "Phoenix robelinii") (SIZE . " 15 GAL") (COLOR) (QTY . 2)))
		   ("SHRUB" ("Arizona Yellow Bells" (BOTANICAL . "Tecoma stans var. agustata") (SIZE . " 5 GAL") (COLOR) (QTY . 2))
			    ("Brave River Sage" (BOTANICAL . "Leucophyllum langmaniae") (SIZE . " 5 GAL") (COLOR) (QTY . 6))
			    ("Chuparosa" (BOTANICAL . "Justicia californica") (SIZE . " 5 GAL") (COLOR) (QTY . 4))
			    ("Pink Fairy Duster" (BOTANICAL . "Calliandra eriophylla") (SIZE . " 5 GAL") (COLOR . "PINK") (QTY . 5))
		   )
		   ("GROUNDCOVER" ("New Gold Lantana" (BOTANICAL . "Lantana hybrid 'New Gold'") (SIZE . " 5 GAL") (COLOR) (QTY . 5)))
		   ("ACCENT" ("Ocotillo" (BOTANICAL . "Fouquieria splendens") (SIZE . " bare root") (COLOR) (QTY . 1))
			     ("Toothless Desert Spoon" (BOTANICAL . "Dasylirion quadrangulatum") (SIZE . " 5 GAL") (COLOR) (QTY . 2))
		   )
		   ("CACTUS" ("Argentine Giant" (BOTANICAL . "Trichocereus candicans") (SIZE . " 5 GAL") (COLOR) (QTY . 1))
			     ("Mexican Fencepost" (BOTANICAL . "Pachycereus marginatus") (SIZE . " 5 GAL") (COLOR) (QTY . 2))
			     ("Purple Prickley Pear" (BOTANICAL . "Opuntia violacea 'Santa Rita'") (SIZE . " 5 GAL") (COLOR) (QTY . 2))
		   )
		   ("LIGHTS" ("Path" (BOTANICAL) (SIZE) (COLOR . "RUST") (QTY . 5))
			     ("Spot" (BOTANICAL) (SIZE) (COLOR . "RUST") (QTY . 5))
			     ("Transformer" (BOTANICAL) (SIZE) (COLOR) (MODEL . "300") (QTY . 1))
		   )
        )
     )
  )
  (PRINC (STRCAT " /></" ax|p ">")) ; Close parent tag 
  (if ax|pp (princ (strcat "</" ax|pp ">"))) ; Close root tag 
  (SETQ	ax|p nil ax|pp nil ax|t nil) ; empty globs 
  (PRINC)
)

 

Any help and/or advice is greatly appreciated. (BTW- this version does not write to a file, that is the easy part. If you choose to test it use textscr to view the results)

 

Thank you.

15 REPLIES 15
Message 2 of 16
martti.halminen
in reply to: mid-awe


@mid-awe wrote:

Hi all,

 

I have been tinkering away at this ever since it was suggested to utilize XML for data transport and storage and then W3C went and stated "If developers DO have sense, future applications will exchange their data in XML." So, it became a priority to me and perhaps you.

 

Many of us, including me, prefer to just stick with (A/V)LISP for as long as AutoCAD will accept it. I did many loong searches for hints of LISP to XML functions finding only the xml-api.lsp and it's great for what it does.

 


If you need to communicate with some external program that doesn't read Lisp s-expressions, XML might make sense, though I have a pretty low opinion of it even for that.

 

For communicating between two Lisp programs (or separate sessions of the same program), XML is total overkill:

 

_$ (setq data '("DrawingData" (DATEDRAWN . "1/6/14") (DRAFTNAME . "Me")
 (REVISIONS ("REVISION1" (WHO . "You") (WHEN . "2/16/2014") (WHAT . "Material colors, CO# 52498"))
     ("REVISION2" (WHO . "Another") (WHEN . "2/24/2014") (WHAT . "SQFT Adjusted"))
     ("REVISION3" (WHO . "You") (WHEN . "2/25/2014") (WHAT . "Something else"))
     ("REVISION4" (WHO . "Other") (WHEN . "2/26/2014") (WHAT . "Add Coping, CO# 52633"))
     ("REVISION5" (WHO . "Another") (WHEN . "2/28/2014") (WHAT . "Add Sand color"))
     ("REVISION6" (WHO . "Me") (WHEN . "3/2/2014") (WHAT . "Revised Per Layout"))
     ("REVISION7" (WHO . "Other") (WHEN . "3/4/2014") (WHAT . "Change Per Super, CO# 52891")))
        (SOFTSCAPE ("PALM" ("Pygmy Palm" (BOTANICAL . "Phoenix robelinii") (SIZE . " 15 GAL") (COLOR) (QTY . 2)))
     ("SHRUB" ("Arizona Yellow Bells" (BOTANICAL . "Tecoma stans var. agustata") (SIZE . " 5 GAL") (COLOR) (QTY . 2))
       ("Brave River Sage" (BOTANICAL . "Leucophyllum langmaniae") (SIZE . " 5 GAL") (COLOR) (QTY . 6))
       ("Chuparosa" (BOTANICAL . "Justicia californica") (SIZE . " 5 GAL") (COLOR) (QTY . 4))
       ("Pink Fairy Duster" (BOTANICAL . "Calliandra eriophylla") (SIZE . " 5 GAL") (COLOR . "PINK") (QTY . 5)))
     ("GROUNDCOVER" ("New Gold Lantana" (BOTANICAL . "Lantana hybrid 'New Gold'") (SIZE . " 5 GAL") (COLOR) (QTY . 5)))
     ("ACCENT" ("Ocotillo" (BOTANICAL . "Fouquieria splendens") (SIZE . " bare root") (COLOR) (QTY . 1))
        ("Toothless Desert Spoon" (BOTANICAL . "Dasylirion quadrangulatum") (SIZE . " 5 GAL") (COLOR) (QTY . 2)))
     ("CACTUS" ("Argentine Giant" (BOTANICAL . "Trichocereus candicans") (SIZE . " 5 GAL") (COLOR) (QTY . 1))
        ("Mexican Fencepost" (BOTANICAL . "Pachycereus marginatus") (SIZE . " 5 GAL") (COLOR) (QTY . 2))
        ("Purple Prickley Pear" (BOTANICAL . "Opuntia violacea 'Santa Rita'") (SIZE . " 5 GAL") (COLOR) (QTY . 2)))
     ("LIGHTS" ("Path" (BOTANICAL) (SIZE) (COLOR . "RUST") (QTY . 5))
        ("Spot" (BOTANICAL) (SIZE) (COLOR . "RUST") (QTY . 5))
        ("Transformer" (BOTANICAL) (SIZE) (COLOR) (MODEL . "300") (QTY . 1))))))


("DrawingData" (DATEDRAWN . "1/6/14") (DRAFTNAME . "Me") (REVISIONS ("REVISION1" (WHO . "You") (WHEN . "2/16/2014") (WHAT . "Material colors, CO# 52498")) ("REVISION2" (WHO . "Another") (WHEN . "2/24/2014") (WHAT . "SQFT Adjusted")) ("REVISION3" (WHO . "You") (WHEN . "2/25/2014") (WHAT . "Something else")) ("REVISION4" (WHO . "Other") (WHEN . "2/26/2014") (WHAT . "Add Coping, CO# 52633")) ("REVISION5" (WHO . "Another") (WHEN . "2/28/2014") (WHAT . "Add Sand color")) ("REVISION6" (WHO . "Me") (WHEN . "3/2/2014") (WHAT . "Revised Per Layout")) ("REVISION7" (WHO . "Other") (WHEN . "3/4/2014") (WHAT . "Change Per Super, CO# 52891"))) (SOFTSCAPE ("PALM" ("Pygmy Palm" (BOTANICAL . "Phoenix robelinii") (SIZE . " 15 GAL") (COLOR) (QTY . 2))) ("SHRUB" ("Arizona Yellow Bells" (BOTANICAL . "Tecoma stans var. agustata") (SIZE . " 5 GAL") (COLOR) (QTY . 2)) ("Brave River Sage" (BOTANICAL . "Leucophyllum langmaniae") (SIZE . " 5 GAL") (COLOR) (QTY . 6)) ("Chuparosa" (BOTANICAL . "Justicia californica") (SIZE . " 5 GAL") (COLOR) (QTY . 4)) ("Pink Fairy Duster" (BOTANICAL . "Calliandra eriophylla") (SIZE . " 5 GAL") (COLOR . "PINK") (QTY . 5))) ("GROUNDCOVER" ("New Gold Lantana" (BOTANICAL . "Lantana hybrid 'New Gold'") (SIZE . " 5 GAL") (COLOR) (QTY . 5))) ("ACCENT" ("Ocotillo" (BOTANICAL . "Fouquieria splendens") (SIZE . " bare root") (COLOR) (QTY . 1)) ("Toothless Desert Spoon" (BOTANICAL . "Dasylirion quadrangulatum") (SIZE . " 5 GAL") (COLOR) (QTY . 2))) ("CACTUS" ("Argentine Giant" (BOTANICAL . "Trichocereus candicans") (SIZE . " 5 GAL") (COLOR) (QTY . 1)) ("Mexican Fencepost" (BOTANICAL . "Pachycereus marginatus") (SIZE . " 5 GAL") (COLOR) (QTY . 2)) ("Purple Prickley Pear" (BOTANICAL . "Opuntia violacea 'Santa Rita'") (SIZE . " 5 GAL") (COLOR) (QTY . 2))) ("LIGHTS" ("Path" (BOTANICAL) (SIZE) (COLOR . "RUST") (QTY . 5)) ("Spot" (BOTANICAL) (SIZE) (COLOR . "RUST") (QTY . 5)) ("Transformer" (BOTANICAL) (SIZE) (COLOR) (MODEL . "300") (QTY . 1)))))

 


_$ (setq str (vl-prin1-to-string data))


"(\"DrawingData\" (DATEDRAWN . \"1/6/14\") (DRAFTNAME . \"Me\") (REVISIONS (\"REVISION1\" (WHO . \"You\") (WHEN . \"2/16/2014\") (WHAT . \"Material colors, CO# 52498\")) (\"REVISION2\" (WHO . \"Another\") (WHEN . \"2/24/2014\") (WHAT . \"SQFT Adjusted\")) (\"REVISION3\" (WHO . \"You\") (WHEN . \"2/25/2014\") (WHAT . \"Something else\")) (\"REVISION4\" (WHO . \"Other\") (WHEN . \"2/26/2014\") (WHAT . \"Add Coping, CO# 52633\")) (\"REVISION5\" (WHO . \"Another\") (WHEN . \"2/28/2014\") (WHAT . \"Add Sand color\")) (\"REVISION6\" (WHO . \"Me\") (WHEN . \"3/2/2014\") (WHAT . \"Revised Per Layout\")) (\"REVISION7\" (WHO . \"Other\") (WHEN . \"3/4/2014\") (WHAT . \"Change Per Super, CO# 52891\"))) (SOFTSCAPE (\"PALM\" (\"Pygmy Palm\" (BOTANICAL . \"Phoenix robelinii\") (SIZE . \" 15 GAL\") (COLOR) (QTY . 2))) (\"SHRUB\" (\"Arizona Yellow Bells\" (BOTANICAL . \"Tecoma stans var. agustata\") (SIZE . \" 5 GAL\") (COLOR) (QTY . 2)) (\"Brave River Sage\" (BOTANICAL . \"Leucophyllum langmaniae\") (SIZE . \" 5 GAL\") (COLOR) (QTY . 6)) (\"Chuparosa\" (BOTANICAL . \"Justicia californica\") (SIZE . \" 5 GAL\") (COLOR) (QTY . 4)) (\"Pink Fairy Duster\" (BOTANICAL . \"Calliandra eriophylla\") (SIZE . \" 5 GAL\") (COLOR . \"PINK\") (QTY . 5))) (\"GROUNDCOVER\" (\"New Gold Lantana\" (BOTANICAL . \"Lantana hybrid 'New Gold'\") (SIZE . \" 5 GAL\") (COLOR) (QTY . 5))) (\"ACCENT\" (\"Ocotillo\" (BOTANICAL . \"Fouquieria splendens\") (SIZE . \" bare root\") (COLOR) (QTY . 1)) (\"Toothless Desert Spoon\" (BOTANICAL . \"Dasylirion quadrangulatum\") (SIZE . \" 5 GAL\") (COLOR) (QTY . 2))) (\"CACTUS\" (\"Argentine Giant\" (BOTANICAL . \"Trichocereus candicans\") (SIZE . \" 5 GAL\") (COLOR) (QTY . 1)) (\"Mexican Fencepost\" (BOTANICAL . \"Pachycereus marginatus\") (SIZE . \" 5 GAL\") (COLOR) (QTY . 2)) (\"Purple Prickley Pear\" (BOTANICAL . \"Opuntia violacea 'Santa Rita'\") (SIZE . \" 5 GAL\") (COLOR) (QTY . 2))) (\"LIGHTS\" (\"Path\" (BOTANICAL) (SIZE) (COLOR . \"RUST\") (QTY . 5)) (\"Spot\" (BOTANICAL) (SIZE) (COLOR . \"RUST\") (QTY . 5)) (\"Transformer\" (BOTANICAL) (SIZE) (COLOR) (MODEL . \"300\") (QTY . 1)))))"

 

;; at this stage you could write this to a file, and later read it to a string in another session with READ-LINE. Converting the result back to a list is just a READ call after that:


_$ (setq in (read str))


("DrawingData" (DATEDRAWN . "1/6/14") (DRAFTNAME . "Me") (REVISIONS ("REVISION1" (WHO . "You") (WHEN . "2/16/2014") (WHAT . "Material colors, CO# 52498")) ("REVISION2" (WHO . "Another") (WHEN . "2/24/2014") (WHAT . "SQFT Adjusted")) ("REVISION3" (WHO . "You") (WHEN . "2/25/2014") (WHAT . "Something else")) ("REVISION4" (WHO . "Other") (WHEN . "2/26/2014") (WHAT . "Add Coping, CO# 52633")) ("REVISION5" (WHO . "Another") (WHEN . "2/28/2014") (WHAT . "Add Sand color")) ("REVISION6" (WHO . "Me") (WHEN . "3/2/2014") (WHAT . "Revised Per Layout")) ("REVISION7" (WHO . "Other") (WHEN . "3/4/2014") (WHAT . "Change Per Super, CO# 52891"))) (SOFTSCAPE ("PALM" ("Pygmy Palm" (BOTANICAL . "Phoenix robelinii") (SIZE . " 15 GAL") (COLOR) (QTY . 2))) ("SHRUB" ("Arizona Yellow Bells" (BOTANICAL . "Tecoma stans var. agustata") (SIZE . " 5 GAL") (COLOR) (QTY . 2)) ("Brave River Sage" (BOTANICAL . "Leucophyllum langmaniae") (SIZE . " 5 GAL") (COLOR) (QTY . 6)) ("Chuparosa" (BOTANICAL . "Justicia californica") (SIZE . " 5 GAL") (COLOR) (QTY . 4)) ("Pink Fairy Duster" (BOTANICAL . "Calliandra eriophylla") (SIZE . " 5 GAL") (COLOR . "PINK") (QTY . 5))) ("GROUNDCOVER" ("New Gold Lantana" (BOTANICAL . "Lantana hybrid 'New Gold'") (SIZE . " 5 GAL") (COLOR) (QTY . 5))) ("ACCENT" ("Ocotillo" (BOTANICAL . "Fouquieria splendens") (SIZE . " bare root") (COLOR) (QTY . 1)) ("Toothless Desert Spoon" (BOTANICAL . "Dasylirion quadrangulatum") (SIZE . " 5 GAL") (COLOR) (QTY . 2))) ("CACTUS" ("Argentine Giant" (BOTANICAL . "Trichocereus candicans") (SIZE . " 5 GAL") (COLOR) (QTY . 1)) ("Mexican Fencepost" (BOTANICAL . "Pachycereus marginatus") (SIZE . " 5 GAL") (COLOR) (QTY . 2)) ("Purple Prickley Pear" (BOTANICAL . "Opuntia violacea 'Santa Rita'") (SIZE . " 5 GAL") (COLOR) (QTY . 2))) ("LIGHTS" ("Path" (BOTANICAL) (SIZE) (COLOR . "RUST") (QTY . 5)) ("Spot" (BOTANICAL) (SIZE) (COLOR . "RUST") (QTY . 5)) ("Transformer" (BOTANICAL) (SIZE) (COLOR) (MODEL . "300") (QTY . 1)))))


_$ (equal data in)
T

 

 

--

 

Message 3 of 16
mid-awe
in reply to: martti.halminen


@martti.halminen wrote:

If you need to communicate with some external program that doesn't read Lisp s-expressions, XML might make sense, though I have a pretty low opinion of it even for that.

 

For communicating between two Lisp programs (or separate sessions of the same program), XML is total overkill:

 


XML is overkill for what you describe. XDATA & LDATA are perfect for that sort of thing and is what I've been doing to form my Association lists. I highly recommend the internal dictionary "for communicating between two Lisp programs (or separate sessions of the same program)".

 

The need to communicate with external programs hosted on a webserver or closed networks or even making the data accessible to users that have no access to AutoCAD or any proprietary software is a common issue and is a good reason for the existence of XML. I used CSV for this in the past, but in a very short time the XML format has shown it's superiority. A simple XML file is esily read with nothing more than a web browser but just as easily parsed into a database. Something as common as javascript can utilize the data and nothing more than XSLT is required to mold it into HTML. 

 

The examples can go on and on. While I respect your opinion, I also believe that you are incorrect. Adoption of open standards can "make or break" professionals, big and small. Also, if XML is a bad idea then Autodesk likely would not have woven it into their family of products. Am I wrong?

 

 

Thank you.

Message 4 of 16
mid-awe
in reply to: mid-awe

Freshening up my search uncovered this recent thread. Reliable Assoc to XML

It appears that I'm not the only one pursuing this avenue. 

Message 5 of 16
hmsilva
in reply to: mid-awe

Hi mid-awe,

 

it's not an easy code to do.

I don't have AutoCAD in this laptop, if if no one step in with some ideas, next week I'll see what I can do.

 

Cheers

Henrique

EESignature

Message 6 of 16
diagodose2009
in reply to: mid-awe

You try our XML-preprocessor

http://www.puiubrat.3x.ro/carto3A/kiturvlx/pp_topolt_anexa1a.rar

 

you load pp_topo_anexa1.vlx

you enter the command Q2

you select any file from folder \inc

If you are happy, then you  send the private message to me.........

Regards...

Message 7 of 16
mid-awe
in reply to: hmsilva

Thank you Henrique. The most challenging part for me is closing the tags. I'm looking at a global containing a list of parents that I can read back as needed and deleting the parents from the list as they are closed. Once the parent list is empty, the root must be closed and the application exits. This is where I stand on the logic. (Everything is converted to a string so that no qualities are lost even for reals.)
Message 8 of 16
mid-awe
in reply to: diagodose2009

I tried the link and received an error. Not sure the issue because I cannot read the language, but I feel that this project should remain open source for the benefit of the community. Yet, thank you.
Message 9 of 16
martti.halminen
in reply to: mid-awe


@mid-awe wrote:

@martti.halminen wrote:

If you need to communicate with some external program that doesn't read Lisp s-expressions, XML might make sense, though I have a pretty low opinion of it even for that.

 

For communicating between two Lisp programs (or separate sessions of the same program), XML is total overkill:

 


XML is overkill for what you describe. XDATA & LDATA are perfect for that sort of thing and is what I've been doing to form my Association lists. I highly recommend the internal dictionary "for communicating between two Lisp programs (or separate sessions of the same program)".

 

The need to communicate with external programs hosted on a webserver or closed networks or even making the data accessible to users that have no access to AutoCAD or any proprietary software is a common issue and is a good reason for the existence of XML. I used CSV for this in the past, but in a very short time the XML format has shown it's superiority. A simple XML file is esily read with nothing more than a web browser but just as easily parsed into a database. Something as common as javascript can utilize the data and nothing more than XSLT is required to mold it into HTML. 

 

The examples can go on and on. While I respect your opinion, I also believe that you are incorrect. Adoption of open standards can "make or break" professionals, big and small. Also, if XML is a bad idea then Autodesk likely would not have woven it into their family of products. Am I wrong?

 


The dictionary approach only works if there is a drawing to use as communication medium. In that case, I typically use LDATA. XDATA is too complicated for my taste, so as long as I don't need to communicate with ARX applications, I avoid it.

- In my application, the communication is between an AutoLISP program and a Common Lisp program, a drawing is only produced afterwards.

 

If you need to communicate with the outside world, XML might make sense, but if you control both ends, a Lisp-only approach is far simpler.

 

- In my experience, for something to be endorsed by Autodesk (or Microsoft) is generally a good indication that I would be happier using something else. For example, AcadM 2005 user interface definition as .mnu was about 2500 lines. The same as XML in 2006 was 27000 lines. Not really a compact representation, no wonder they don't want people editing it themselves...

 

--

 

Message 10 of 16
martti.halminen
in reply to: mid-awe


@mid-awe wrote:
Thank you Henrique. The most challenging part for me is closing the tags. I'm looking at a global containing a list of parents that I can read back as needed and deleting the parents from the list as they are closed. Once the parent list is empty, the root must be closed and the application exits. This is where I stand on the logic. (Everything is converted to a string so that no qualities are lost even for reals.)

I think you are doing this unnecessarily complicated. Just let the function call stack handle this for you, by doing the s-exp to xml translation recursively.

So for any kind of Lisp item write a generic translator:

 

1. Print out relevant opening tags

2. Iterate through the contents, calling the translator for each item.

   After those calls return,

3. Print out the closing tags for this level.

(only for this level, any call to translator handles its own level)

 

--

 

 

 

 

Message 11 of 16
mid-awe
in reply to: martti.halminen

Thank you. That is a good idea, but you may be over looking that the nesting can go to an unlimited level. 20-30 levels deep it can be tricky sorting without the parent list. Some elements make sense to self close if only attributes (descriptors) exist while something a vague as additional notes or miscellany would never work without full node.
Message 12 of 16
mid-awe
in reply to: martti.halminen

Looking back over your suggestion, I think I misunderstood. You may be onto something here, but an active list still seems to be necessary for deep nesting.
Message 13 of 16
mid-awe
in reply to: mid-awe

I've played around a bit with this but even the examples won't work. So far as I can tell.
Message 14 of 16
mid-awe
in reply to: mid-awe

For my own needs I'll use custom subfunctions to convert my assoc lists, but I'l continue working on the generic function as described in the first post of this thread for anyone interested. I'm still convinced that a generic function as described will be a benefit to the community.

Message 15 of 16
hmsilva
in reply to: mid-awe

Sorry mid-awe,

I have not forgotten your code, i'm having some health problems, so I'm not able to give you much help right now...

 

But when possible, I´ll see what can I do.

Henrique

 

EESignature

Message 16 of 16
mid-awe
in reply to: hmsilva

Henrique, by all means take care of you first my friend.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost