Hi ,
writing a small application in C which has to create an XML document by
reading a binary format file. Trying to get the indentation right by
using a depth global variable which will insert appropriate number of
tab spaces depending up on the depth.
Is there any way that this can be done using a macro.
So , something like
#define INSERTTAB (x) /* not sure what will come here */
INSERTTAB (depth)
thanks in advance,
vivekian 5 2249 vi********@gmai l.com wrote: Hi ,
writing a small application in C which has to create an XML document by reading a binary format file. Trying to get the indentation right by using a depth global variable which will insert appropriate number of tab spaces depending up on the depth.
Is there any way that this can be done using a macro.
Why a macro, what's wrong with a function?
--
Ian Collins. vi********@gmai l.com wrote: writing a small application in C which has to create an XML document by reading a binary format file. Trying to get the indentation right by using a depth global variable which will insert appropriate number of tab spaces depending up on the depth.
Why not just use a library that already handles creating an XML
rather than re-inventing the wheel? XML is complicated enough that
it's unlikely you're producing valid XML anyway.
For what it's worth, if you really have to do it yourself manually
for some reason, the simplest way is to create a tree as an intermediate
form. Then walk the tree and spit out open tags when you first visit
a node and close tags when you leave the node. (That ignores the
"<foo/>"-style tags where in effect the open and close tags are
combined, but that's a simple extension.)
- Logan
On 2006-04-27, vi********@gmai l.com <vi********@gma il.com> wrote: Hi ,
writing a small application in C which has to create an XML document by reading a binary format file. Trying to get the indentation right by using a depth global variable which will insert appropriate number of tab spaces depending up on the depth.
Is there any way that this can be done using a macro.
So , something like
#define INSERTTAB (x) /* not sure what will come here */
INSERTTAB (depth)
The only reason I can think of for a macro (rather than a function) is
because you want a macro that expands to a string literal:
printf(INSERTTA B(n)"%s\n", tag);
which needs to expand to:
printf("\t\t\t\ t""%s\n", "hello");
I'm fairly sure there's no way to do this-- even if the C preprocessor
had more functionality, n isn't known until runtime, so it's got to be
runtime code that "prints" the tabs one way or another.
You could try:
printf("%s%s\n" , make_tabs(n), tag);
where make_tabs returns a string of tabs. But then you have to worry
about allocating strings. There are various options, but none of them
are very nice if the indent level gets high.
So a function to actually put the tabs in is your best bet I would say:
void insert_tabs(FIL E *fp, unsigned n)
{
...
}
insert_tabs(std out, 4);
printf("%s\n", tag);
The other option you've got is perhaps generate the xml without any
indentation at all, and then pipe it through one of the many xml
indentation programs that exist-- the xslt program to do this is
practically a one-liner.
In article <sl************ *********@bowse r.marioworld>, Ben C <sp******@spam. eggs> writes: On 2006-04-27, vi********@gmai l.com <vi********@gma il.com> wrote: writing a small application in C which has to create an XML document by reading a binary format file. Trying to get the indentation right by using a depth global variable which will insert appropriate number of tab spaces depending up on the depth.
Is there any way that this can be done using a macro.
So , something like
#define INSERTTAB (x) /* not sure what will come here */
INSERTTAB (depth) The only reason I can think of for a macro (rather than a function) is because you want a macro that expands to a string literal:
printf(INSERTTA B(n)"%s\n", tag);
which needs to expand to:
printf("\t\t\t\ t""%s\n", "hello");
I'm fairly sure there's no way to do this-- even if the C preprocessor had more functionality, n isn't known until runtime, so it's got to be runtime code that "prints" the tabs one way or another.
You're insufficiently perverse.
-----
#include <stdio.h>
#define INSERTTAB(n) (8-(n))+"\t\t\t\t\ t\t\t\t"
int main(void)
{
int i;
for (i=0; i<=8; i++)
puts(INSERTTAB( i) "*");
return 0;
}
-----
Obviously this is fragile, limited, and generally awful, but it does
work for the specific case you cited.
You could try:
printf("%s%s\n" , make_tabs(n), tag);
where make_tabs returns a string of tabs. But then you have to worry about allocating strings. There are various options, but none of them are very nice if the indent level gets high.
Here I'd almost be ready to recommend a macro that indexed into a
long constant string of tabs. No need to allocate anything, if you
can set a maximum on your indentation level. You could also limit
the indentation level in the macro, though that requires evaluating
the argument more than once except for some restricted cases (eg
where you can use binary-and or a similar operation to truncate it).
--
Michael Wojcik mi************@ microfocus.com
The lark is exclusively a Soviet bird. The lark does not like the
other countries, and lets its harmonious song be heard only over the
fields made fertile by the collective labor of the citizens of the
happy land of the Soviets. -- D. Bleiman
On 2006-05-02, Michael Wojcik <mw*****@newsgu y.com> wrote: In article <sl************ *********@bowse r.marioworld>, Ben C <sp******@spam. eggs> writes: On 2006-04-27, vi********@gmai l.com <vi********@gma il.com> wrote: > > writing a small application in C which has to create an XML document by > reading a binary format file. Trying to get the indentation right by > using a depth global variable which will insert appropriate number of > tab spaces depending up on the depth. > > Is there any way that this can be done using a macro. > > So , something like > > #define INSERTTAB (x) /* not sure what will come here */ > > INSERTTAB (depth)
The only reason I can think of for a macro (rather than a function) is because you want a macro that expands to a string literal:
printf(INSERTTA B(n)"%s\n", tag);
which needs to expand to:
printf("\t\t\t\ t""%s\n", "hello");
I'm fairly sure there's no way to do this-- even if the C preprocessor had more functionality, n isn't known until runtime, so it's got to be runtime code that "prints" the tabs one way or another.
You're insufficiently perverse.
----- #include <stdio.h>
#define INSERTTAB(n) (8-(n))+"\t\t\t\t\ t\t\t\t"
int main(void) { int i; for (i=0; i<=8; i++) puts(INSERTTAB( i) "*");
return 0; } -----
Obviously this is fragile, limited, and generally awful, but it does work for the specific case you cited.
Most ingenious! You could try:
printf("%s%s\n" , make_tabs(n), tag);
where make_tabs returns a string of tabs. But then you have to worry about allocating strings. There are various options, but none of them are very nice if the indent level gets high.
Here I'd almost be ready to recommend a macro that indexed into a long constant string of tabs. No need to allocate anything, if you can set a maximum on your indentation level.
I did think of that one, and lumped it with "solutions that aren't very
nice if the indent level gets high". This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kerri McDonald |
last post by:
We have an application where the user fills out many screens and when
they are done, we are supposed to display the text they entered in a
word or excel format. That is fairly easily accomplished by changing
the content type in the response object.
On one of the screens where they enter data, they also have the
ability to upload a word document containing additional information.
This is also not a problem, and is working fine.
Now they...
|
by: svend |
last post by:
I'm messing with some code here... Lets say I have this array:
a1 = ;
And I apply slice(0) on it, to create a copy:
a2 = a1.slice(0);
But this isn't a true copy. If I go a1 = 42, and then
alert(a2) I will see 42 there too. I'm doubting, but I was
|
by: Russ |
last post by:
Hi All,
I have a problem getting the following simple example
of "document.write" creating a script on the fly
to work in all html browsers.
It works in I.E., Firefox, and Netscape 7 above.
It doesn't seem to work in Netscape 4. Am I missing
something with it? When I look at page source in
Netscape 4 the script isn't even shown.
Can Netscape 4 create scripts on the fly at all?
|
by: pshvarts |
last post by:
(I'm new in SOAP)
I get some wsdl file (from apache service ). I tried creating SOAP client
with .NET - trying to add Web Reference and get error like: "Custom tool
error: Unable to import WebService/Schema. Unable to import binding..."
I thought may be wsdl file is not good enough (it was created with qsoap
toolkit), so I paste-copy sample from
http://www.w3.org/TR/2001/NOTE-wsdl-20010315#_wsdl (will paste below) and
receive same error...
|
by: Adam Tilghman |
last post by:
Hi all,
I have found that IE doesn't seem to respect the <SELECT> "multiple"
attribute when set using DOM methods, although the attribute/property
seems to exist and is updated properly. Those changes just don't make
it onto the screen.
Am I doing something wrong here?
If not, is there a better feature test I can use than
"appName.match()"?
| |
by: sam |
last post by:
Hi all,
I am dynamically creating a table rows and inerting radio buttons which
are also dynamically created. Everything works fine in Firefox as
expected. But I am not able to select radio buttons in IE. It does not
even throw any errors. I have searched over the net but could not find
anyhelp. Hope some experts here could help me.
Here is part my code that dynamically generates the radio buttons, I
cannot paste the entire code as it is...
|
by: GRenard |
last post by:
Hi,
I'm trying just to display a table on a webpage using DOM elements
created dynamically.
I really don't understand why IE doesn't display the document
successfully...
If I make a copy/paste of the output, I can see the data.
Mozilla displays successfully a table... Check this little code :
|
by: patrickkellogg |
last post by:
I have this code when you click the buttom is suppose to add a job
history. it works with firefox, opera, but not ie. (please note -
new entries don't have all the elements in them yet, but enough to get
the idea).
Here is the code:
-----------------------------------------------------------------
<html>
|
by: skyson2ye |
last post by:
Hi, guys:
I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem, and I have spent three days trying to debug but to no avail.
Everything is OK when there are only two dependent list boxes, but when adding the third child list box, a problem appears: if I populate the third box only with the value: new...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |