Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-07

another xml question

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Chris Moody

Hi all,

For the app I'm writing, it will have 3 elements in the XML document it reads. The first 2 will only have one child element. The third one will be from 1 to whatever.

I'm also designing the app that will create the XML file for the app to read also, so a couple of questions:

Would it be easiest to introduce a fourth element to the XML that says how many children the 3rd element has? Or is there an easy way already to get this and just run a for next loop to read each child?

Thanks in advance!

Chris

Reply by email

Marc Santhoff
to Chris Moody
Chris Moody wrote
Would it be easiest to introduce a fourth element to the XML that says how many children the 3rd element has? Or is there an easy way already to get this and just run a for next loop to read each child?

Maybe sth. like this would do:

<counted_element count=3>
<child>1>/child>
<child>2>/child>
<child>3>/child>
</counted_element>

or similar. Besides making the count an attribute of the root node of counted elements you could simply use a standard pascal loop:

n: XMLNode;

{ this is only pseude code ... }
while (xmldoc.hasMoreChilds()) do begin

	n := getChild();
	... process n ...

end:

For real code http://wiki.freepascal.org/XML_Tutorial mwill help.

HTH,
Marc

Marc Santhoff

Reply by email

Chris Moody
to Marc Santhoff

Hi Marc,

Thanks for the feedback. One more question and I think I'm done for now and able to finish the program I'm writing:

If FindNode does not locate a node with the given name, what does it return?

Thanks,

Chris

Marc Santhoff wrote 29 lines
On Fr, 2015-07-24 at 11:57 -0700, Chris Moody wrote: > Would it be easiest to introduce a fourth element to the XML that says > how many children the 3rd element has? Or is there an easy way already > to get this and just run a for next loop to read each child? Maybe sth. like this would do: <counted_element count=3> <child>1>/child> <child>2>/child> <child>3>/child> </counted_element> or similar. Besides making the count an attribute of the root node of counted elements you could simply use a standard pascal loop: n: XMLNode; { this is only pseude code ... } while (xmldoc.hasMoreChilds()) do begin n := getChild(); ... process n ... end: For real code http://wiki.freepascal.org/XML_Tutorial mwill help. HTH, Marc

Reply by email

Marc Santhoff
to Chris Moody
Chris Moody wrote 7 lines
Hi Marc, Thanks for the feedback. One more question and I think I'm done for now and able to finish the program I'm writing: If FindNode does not locate a node with the given name, what does it return?

I don't know. It looks like it would be the first child of the subnode you're working at. I'm not sure if that first child can be a nil pointer, so you need to check yourself or someone else has to answer this question.

But it is easy to jump to the implementation of FindNode() yourself:

1. Put the cursor on the function call to <yourxmldoc>.FindNode()
2. klick the right mouse key
3. in the popped up menu select "Find Declaration of FindNode"
4. hit the keys Shift+down (arrow)

After Step 3 you're shown the class declaration, then after the fourth step the cursor is sitting in the implementation of the method in question. Then you can read the code.

Have fun,
Marc

Show quoted text 38 lines
Thanks, Chris On 07/24/2015 01:34 PM, Marc Santhoff wrote: > On Fr, 2015-07-24 at 11:57 -0700, Chris Moody wrote: > >> Would it be easiest to introduce a fourth element to the XML that says >> how many children the 3rd element has? Or is there an easy way already >> to get this and just run a for next loop to read each child? > Maybe sth. like this would do: > > <counted_element count=3> > <child>1>/child> > <child>2>/child> > <child>3>/child> > </counted_element> > > or similar. Besides making the count an attribute of the root node of > counted elements you could simply use a standard pascal loop: > > n: XMLNode; > > { this is only pseude code ... } > while (xmldoc.hasMoreChilds()) do begin > n := getChild(); > ... process n ... > end: > > For real code http://wiki.freepascal.org/XML_Tutorial mwill help. > > HTH, > Marc > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Marc Santhoff

Reply by email