Jump to content
  • Advertisement
Sign in to follow this  
Daniel Miller

a small XML problem

This topic is 4733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been playing around with XML lately, and I'm finding it to be every bit as good as everyone says. I have encountered my first problem, however. Below is my code (if you say it shouldn't be organized in that way, you are probably right, but I am doing this just to test things). My problem is that <footer> includes the tabs before it when I print it out (using .NET's InnerText method). It only happens when I put regular text into <notice> above <footer>, but if I put the text anywhere else it gets indented. How should I avoid this?
<?xmlversion = "1.0"?>

<library>
	<book>
		<title>Microsoft Visual C# .NET</title>
		<author>John Sharp/Jon Hagger</author>
		<page-count>635</page-count>
	</book>
	<book>
		<title>More Effective C++</title>
		<author>Scott Meyers</author>
		<page-count>318</page-count>
	</book>
	<book>
		<title>Modern C++ Design</title>
		<author>Andrei Alexandrescu</author>
	</book>
	<notice>Please return books on time. Thanks!
		<footer>Thank you for reading.</footer>
	</notice>
</library>






Edit: I should add that I want to be able to avoid this without putting the regular text into a seperate element or attribute, but if that is the only way I am perfectly fine with it. [Edited by - Daniel Miller on June 8, 2005 5:47:37 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Daniel Miller
My problem is that <footer> includes the tabs before it when I print it out (using .NET's InnerText method). It only happens when I put regular text into <notice> above <footer>, but if I put the text anywhere else it gets indented. How should I avoid this?

*** Source Snippet Removed ***

Edit: I should add that I want to be able to avoid this without putting the regular text into a seperate element, but if that is the only way iI am perfectly fine with it.


O_o ? You mean, you have a problem with XML indentation, which is only here in order to help human read, but has no real consequence since only computers are processing XML???? Or am I missing something?

BTW, it is Andrei Alexandrescu, not Alex :)

Regards,

Share this post


Link to post
Share on other sites
I am saying that whitespace is being strangely included in <footer>, and I'm wondering why. It isn't included in any of other nodes.

p.s.: Thanks for the correction, but I really did know that! :P

[Edited by - Daniel Miller on June 8, 2005 5:25:29 PM]

Share this post


Link to post
Share on other sites
Perhaps it's because of the way that footer is formated. have you tried something like:

<notice info="Please return books on time. Thanks!">
<footer>Thank you for reading.</footer>
</notice>



And use the attribute 'info' instead? If not, when you get that string, you can remove all the '\t' in it to "". Not sure of the exact problem, but I say play around with it some. I've been working with XML as well [wink]. I have come across a few problems with formatting, but I just corrected it in my program. Oh well, good luck!

Share this post


Link to post
Share on other sites
Well, I was trying to avoid having to change anything but the formatting, but I may have to do what you said.

As a side question, should you use attributes when the "end user" of the data doesn't need the information, and use elements otherwise? I am confused as to when to use each.

Edit: Forgot to say thanks to both of you for replying. :)
Edit2: I deleted some text by accident.

[Edited by - Daniel Miller on June 8, 2005 5:32:52 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!