Recent

Author Topic: Help me wrap my head around xml  (Read 24118 times)

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: Help me wrap my head around xml
« Reply #15 on: March 15, 2011, 06:18:45 pm »
Ok, before I pull all of my remaining hair out I have a question.  The xml file I'm dealing with appears to be, as one poster commented on, a dump of a data base.  I've been trying to decode how it has it's format laid out and will probably be able to code a nasty piece of something to pull out the data.  Before I do this am I missing something during this process??  Is there a simple way to basically convert the xml back to some kind of database format or a plugin for Lazarus that will greatly decrease my headaches by automating a bit of decoding the hierarchy???   Maybe I'm just looking at it sideways and am not seeing the whole picture but the way this xml file is laid out is making my life extremely painful.

I attached, I hope, a sample text file of just one composite item.

I took out the pricing so management wouldn't have a cow.  :D


This is basically one window with options, don't ask me about it since I'm IT and don't do windows  ::)


I need to get this into a format I can then pull out the basics from to make an import file for our PO system.


What I'm currently trying is to run through the nodes and generate an array of records that have the name and value of the node in it all for each main node (window).  Like I said I can kludge together something and then clean it up but it would be nice if I was 'missing' something and there was an easier way.  :-[

eny

  • Hero Member
  • *****
  • Posts: 1646
Re: Help me wrap my head around xml
« Reply #16 on: March 15, 2011, 10:12:47 pm »
The xml file I'm dealing with appears to be, as one poster commented on, a dump of a data base.
I wonder who that was  :D

What you need to know is the structure of the XML and based on that do your processing.
The XML looks fairly well structured, one of the benefits of it being generated (see image).
It's fairly simple to build a datastructure that containts that hierarchical data.
And it's also fairly straightforward to build some code that processes the XML.
It depends on what you want: if it's just a one off transformation, get your hands dirty and build the code around it.
And if you do need to do some fancy processing (more than once), build more generic code around it to do the in-memory processing.
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

JD

  • Hero Member
  • *****
  • Posts: 1906
Re: Help me wrap my head around xml
« Reply #17 on: March 15, 2011, 11:46:58 pm »
Now you need to read the wiki page about how Lazarus processes XML documents. I agree with eny - the document is well structured so extracting records from it should be easy.
Linux Mint - Lazarus 4.0/FPC 3.2.2,
Windows - Lazarus 4.0/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: Help me wrap my head around xml
« Reply #18 on: March 16, 2011, 01:29:22 pm »
The xml file I'm dealing with appears to be, as one poster commented on, a dump of a data base.
I wonder who that was  :D

What you need to know is the structure of the XML and based on that do your processing.
The XML looks fairly well structured, one of the benefits of it being generated (see image).
It's fairly simple to build a datastructure that containts that hierarchical data.
And it's also fairly straightforward to build some code that processes the XML.
It depends on what you want: if it's just a one off transformation, get your hands dirty and build the code around it.
And if you do need to do some fancy processing (more than once), build more generic code around it to do the in-memory processing.

Ok, so I'm basically on the right track in that I have to walk through the nodes in a serial fashion and pull the data out manually.   I was hoping I could pull this into a in memory database directly and manipulate it there  :(

I did see something about reading the xml file into a memdataset and was trying to figure that out yesterday before I had to leave to keep my hours cut back.  :'(  I'm not a big fan of 'work' but I really hate when I get 'into' a programming problem and have to leave  ;)

 

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: Help me wrap my head around xml
« Reply #19 on: March 16, 2011, 04:12:43 pm »
Here is me being a newbie in pascal/Lazarus, what would be to best/simplest method or data structure I can use so put this data in??  I know best and simplest are usually mutually exclusive but...   I haven't had to deal with a somewhat complicated data set before so I'm kinda floundering around wondering what is the best direction to go??  I was looking at memdatasets earlier which I realized wasn't working for a direct dump of an xml file but would I be better off looking at something like that or just use some kind of multi dimensioned arrays or is there something else that fits more to the type of multi level data I'll be dealing with??

If you look at the xml file I uploaded you'll see that I have levels like, Composite,unit in composite, features in unit and so on and I'll have multiple Composites in an order not to mention standalone units so an order might look like,

 Order/Unit/Features, Order/Composite/feature, Order/Composite/Unit/feature, etc.

Right now I figure I'll have to step through the nodes of the xml and determine what exactly I'm looking at, Unit/Composite/Feature and what it is associated with and dump it into an array of records.

Ideas/Directions/ or 'WTF are you doing it that way fors??'   %)

eny

  • Hero Member
  • *****
  • Posts: 1646
Re: Help me wrap my head around xml
« Reply #20 on: March 16, 2011, 04:34:03 pm »
Keep it simple: every node type is a class (except for the Attributes).
Put lists of the same node type in a TList.
And for the Attributes: use a TStringList and make use of the Name/Value functionality.
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

JD

  • Hero Member
  • *****
  • Posts: 1906
Re: Help me wrap my head around xml
« Reply #21 on: March 16, 2011, 06:22:16 pm »
I did see something about reading the xml file into a memdataset and was trying to figure that out yesterday before I had to leave to keep my hours cut back.  :'(  I'm not a big fan of 'work' but I really hate when I get 'into' a programming problem and have to leave  ;)

Think of the joy, the "rush" you'll get when you finally solve the problem. That should motivate you.  :D
Linux Mint - Lazarus 4.0/FPC 3.2.2,
Windows - Lazarus 4.0/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: Help me wrap my head around xml
« Reply #22 on: March 16, 2011, 06:32:12 pm »
I did see something about reading the xml file into a memdataset and was trying to figure that out yesterday before I had to leave to keep my hours cut back.  :'(  I'm not a big fan of 'work' but I really hate when I get 'into' a programming problem and have to leave  ;)

Think of the joy, the "rush" you'll get when you finally solve the problem. That should motivate you.  :D

Yes, thats me, happy happy joy joy I'm at work.........   >:D

Actually a good programming problem does make the day go by faster, that and cough syrup with codeine   :D  The wife is sick and on it so I'm sure I'll have the same thing in a few days, ah the joys of having her work in a retail environment every bug bouncing around the community is sure to end up im my house.  :'(


mas steindorff

  • Hero Member
  • *****
  • Posts: 555
Re: Help me wrap my head around xml
« Reply #23 on: March 17, 2011, 12:32:51 am »
One of the things to remember about XML is that you do not need to understand everything.  ;D

If you can not handle a <JOHNBOY> section, then just look for the </JOHNBOY> and skip what is between.  note some times the end of section is just /> for single line items.


windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

eny

  • Hero Member
  • *****
  • Posts: 1646
Re: Help me wrap my head around xml
« Reply #24 on: March 17, 2011, 10:05:17 am »
note some times the end of section is just /> for single line items.
The XML parser in Lazarus/FPC does a pretty good job hiding all these nasty details from us  :)
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: Help me wrap my head around xml
« Reply #25 on: March 17, 2011, 03:07:28 pm »
I'm finally starting to get somewhere   :)

I do have a further question about tlists but I'll post that in a new thread.

Thanks

 

TinyPortal © 2005-2018