hello,
i have a java app that constructs an xml from a specific file format
and vice versa.
i've been asked to convert it to c++, but im not an expert in c++,
actually im mere beginner you can say.
i got a couple of questions though:
1- is there any equivalent to java's Stream
classes(ByteArrayInputStream,InputStreamRedare,Dat aInputStream ..)
2- how to open a stream on a byte ( char) array in c++ in order to
read it as text. i have a byte array i need to strip off some bytes
from and then pass it to a text stream.
3- i know strings are ended in '\0' the null character in c++.in the
fil i want to parse, xml-to-be-elements are separated by '\0', how can
i split the read text into strings using '\0' as my delimiter without
confusing c++.
4- the most important : how to parse and construct xml in c++, is
there any api for that and where to find it?
5- last nut not least , since im targetting Windows , would it be
better to use unmanaged Visual C++ . does it have the types i am
looking for,and does it make it easy to accomplish the task ?
oh and i use g++ for windows.
Thanks
regards 12 2599
On 13 Feb., 12:17, "steven acer" <dudest...@gmail.comwrote:
hello,
i have a java app that constructs an xml from a specific file format
and vice versa.
i've been asked to convert it to c++, but im not an expert in c++,
actually im mere beginner you can say.
I am not sure that is a fair "first" job.
i got a couple of questions though:
1- is there any equivalent to java's Stream
classes(ByteArrayInputStream,InputStreamRedare,Dat aInputStream ..)
Yes. For formatted IO you probably need an std::ofstream. For
unformatted/binary, you could use a streambuffer or the C file
iosystem. You better study that.
2- how to open a stream on a byte ( char) array in c++ in order to
read it as text. i have a byte array i need to strip off some bytes
from and then pass it to a text stream.
You should read the documentation and be more specific in your
question here. It's not difficult, but we can't answer without more
knowledge of your problem.
3- i know strings are ended in '\0' the null character in c++.
That is false, actually. C strings are null-terminated, C++ strings
are not.
in the
fil i want to parse, xml-to-be-elements are separated by '\0', how can
i split the read text into strings using '\0' as my delimiter without
confusing c++.
This again depends on your requirements.
4- the most important : how to parse and construct xml in c++, is
there any api for that and where to find it?
There are several nice xml-parsers for C++. A short google should give
you a candidate. Choosing one probably is more of a political decision
to be made by your company.
5- last nut not least , since im targetting Windows , would it be
better to use unmanaged Visual C++ . does it have the types i am
looking for,and does it make it easy to accomplish the task ?
oh and i use g++ for windows.
There is only one C++ - namely the language we discuss in this
newsgroup. Microsoft has created a new language which they for some
reason call "managed C++", but it is not C++. "Managed C++" might
likely be a fine language for programming, but it can't be used for
porting to C++.
/Peter
On Tue, 13 Feb 2007 04:00:26 -0800, peter koch wrote:
On 13 Feb., 12:17, "steven acer" wrote:
>hello, i have a java app that constructs an xml from a specific file format and vice versa. i've been asked to convert it to c++, but im not an expert in c++, actually im mere beginner you can say.
I am not sure that is a fair "first" job.
>i got a couple of questions though: 1- is there any equivalent to java's Stream classes(ByteArrayInputStream,InputStreamRedare,Da taInputStream ..)
Yes. For formatted IO you probably need an std::ofstream.
(did you mean std::ifstream ?)
For unformatted/binary, you could use a streambuffer or the C file
iosystem. You better study that.
Easier to use one of the std::ifstream::get() functions, or better
std::ifstream::read(); but you may not need to use unformatted input - see
below.
>2- how to open a stream on a byte ( char) array in c++ in order to read it as text. i have a byte array i need to strip off some bytes from and then pass it to a text stream.
You should read the documentation and be more specific in your
question here. It's not difficult, but we can't answer without more
knowledge of your problem.
>3- i know strings are ended in '\0' the null character in c++.
That is false, actually. C strings are null-terminated, C++ strings
are not.
To be more precise: the C++ string class std::string is probably not
implemented using null-terminated character arrays (the standard does not
require this).
>in the fil i want to parse, xml-to-be-elements are separated by '\0', how can i split the read text into strings using '\0' as my delimiter without confusing c++.
Perhaps you could use std::getline() specifying '\0' as delimiter to read
your xml elements straight into std::string's. You won't confuse C++ that
way, you won't have to mess around with memory management and your
elements end up in nice C++-style strings.
/.../
--
Lionel B
On 13 Feb., 13:48, Lionel B <m...@privacy.netwrote:
On Tue, 13 Feb 2007 04:00:26 -0800, peter koch wrote:
On 13 Feb., 12:17, "steven acer" wrote:
[snip]
Yes. For formatted IO you probably need an std::ofstream.
(did you mean std::ifstream ?)
Yup.
>
For unformatted/binary, you could use a streambuffer or the C file
iosystem. You better study that.
Easier to use one of the std::ifstream::get() functions, or better
std::ifstream::read(); but you may not need to use unformatted input - see
below.
What is "easier" depends. My experience with binary IO in C++ has
either been a layered above C file io for simple IO jobs as the OP has
or going "to the metal" for IO with high performance requirements (or
large files: so far as I know MSVC still only supports IO for files up
to 2GB).
[snip]
3- i know strings are ended in '\0' the null character in c++.
That is false, actually. C strings are null-terminated, C++ strings
are not.
To be more precise: the C++ string class std::string is probably not
implemented using null-terminated character arrays (the standard does not
require this).
The standard allows embedded nulls and also has other requirements
that forbids std::string to be implemented as a null-terminated
string.
[snip]
/Peter
Thanks for the replies guys.
first i dont wanna study and delve into c++ because im a java
developer and im doing this conversion for *just 1 time*.besides it's
a really small app.so any help i can get is really appreciated.
ok let's see
To be more precise: the C++ string class std::string is probably not
implemented using null-terminated character arrays (the standard does not
require this).
Perhaps you could use std::getline() specifying '\0' as delimiter to read
your xml elements straight into std::string's. You won't confuse C++ that
way, you won't have to mess around with memory management and your
elements end up in nice C++-style strings.
i think you got me wrong . i have a .trs(whatever) file which i want
to read and generate an xml based upon its contents.
in this file i have data separated by null characters, in java i would
have done read the contents of the trs file into a string
and then myString.split("\0") would return me an array of tokens.is
there anything similar in c++ to split a string using a
delimiter( since strings do not end with "\0" no problem).
regarding question 2:
=====================
>2- how to open a stream on a byte ( char) array in c++ in order to read it as text. i have a byte array i need to strip off some bytes from and then pass it to a text stream.
an example of java code would clear things up : BufferedReader in=new
BufferedReader(new InputStreamReader(new ByteArrayInputStream(data)));
data is an array of bytes (char). at the end of this statement i would
be reading text characters.that is what i meant by opening a text
stream on a byte array.can this be done in c++?
1 more thing is there a way to copy an array to another in c++ other
then looping through the array ?
thanks alot
On Tue, 13 Feb 2007 07:12:03 -0800, steven acer wrote:
[snip]
>Perhaps you could use std::getline() specifying '\0' as delimiter to read your xml elements straight into std::string's. You won't confuse C++ that way, you won't have to mess around with memory management and your elements end up in nice C++-style strings.
i think you got me wrong .
Not necessarily. Read on.
i have a .trs(whatever) file which i want
to read and generate an xml based upon its contents.
in this file i have data separated by null characters, in java i would
have done read the contents of the trs file into a string
and then myString.split("\0") would return me an array of tokens.is
there anything similar in c++ to split a string using a
delimiter( since strings do not end with "\0" no problem).
Code snippet off the top of my head (not tested!):
#include <ifstream>
#include <string>
#include <vector>
ifstream ifs(your_trs_file);
if (!ifs) ... // handle file open failure
std::string str;
std::vector<std::stringtoken;
while (!getline(ifs,str,'\0')) token.push_back(str);
now token[i] is the i-th token from your file.
[snip]
--
Lionel B
#include <ifstream>
#include <string>
#include <vector>
ifstream ifs(your_trs_file);
if (!ifs) ... // handle file open failure
std::string str;
std::vector<std::stringtoken;
while (!getline(ifs,str,'\0')) token.push_back(str);
now token[i] is the i-th token from your file.
all right i was not that far , but what about consecutive nulls like
'\0\0' ?
i've googled for a c++ xml parser and found apache's xercesc-c++
(kinda like SAX), but it just parses xml as i've seen,do you know of
any that constructs or transforms xml ?
one more silly question - *sorry found nothing about it on the web* -
how to make c++ ( or the preprocessor) find the following include
#include <xercesc/dom/DOM.hpp- or any other
does it have to point to some file on my filesystem , how does c++
look for it?
and regarding byte arrays, any suggestions ?
many thanks
steven acer wrote:
>
i've googled for a c++ xml parser and found apache's xercesc-c++
(kinda like SAX), but it just parses xml as i've seen,do you know of
any that constructs or transforms xml ?
I though xerces did that too.
>
one more silly question - *sorry found nothing about it on the web* -
how to make c++ ( or the preprocessor) find the following include
#include <xercesc/dom/DOM.hpp- or any other
does it have to point to some file on my filesystem , how does c++
look for it?
C++ does not specify how the file is found. That depends on your
compiler. Consult your compiler docs.
and regarding byte arrays, any suggestions ?
In C++ you would use an std::istringstream which is a stream that reads
from a string, you would need to convert you byte array into a string
first. Simple enough unless you have character encoding issues (you seem
to use byte and char interchangeably so I'm not sure exactly what you need).
>
many thanks
john
On Tue, 13 Feb 2007 08:46:54 -0800, steven acer wrote:
> #include <ifstream> #include <string> #include <vector>
ifstream ifs(your_trs_file); if (!ifs) ... // handle file open failure
std::string str; std::vector<std::stringtoken; while (!getline(ifs,str,'\0')) token.push_back(str);
now token[i] is the i-th token from your file.
all right i was not that far , but what about consecutive nulls like
'\0\0' ?
Well, how do you want to treat them? If there's nothing between delimiters
('\0' in this case) you will end up with a token comprising an empty
string; i.e. a string containing no characters, or of length zero, if you
like.
[...]
and regarding byte arrays, any suggestions ?
I'ts not clear to me what you want "byte arrays" *for* so it's difficult
to suggest anything... C++ certainly has arrays and I suspect that "byte"
probably translates to the C++ "char" type. But if all you want is
something that behaves like a string of characters then std::string is the
way to go. If you want to do formatted I/O with strings then you might
look at std::stringstream.
--
Lionel B
I though xerces did that too.
can you please show me a small example of writing xml to a file.
C++ does not specify how the file is found. That depends on your
compiler. Consult your compiler docs.
i did . i'm usig g++ for windows.it says to use the -
I<include_files_diretoryoption while compiling.
but it did not work !
it just could not find the files
i have in my header file
#include <xerces/dom/DOM.hpp>
on the command line typing : -Ic:\includes as an option for g++ never
works though the hierarchy xerces\dom\DOM.hpp is in c:\includes.
im starting to think i need an IDE for this small task.
do you know of any free IDE that provies intelliscence help, i'm using
the CDT plugin for eclipse but it's ot much of an environment.
i've googled for a c++ xml parser and found apache's xercesc-c++
(kinda like SAX), but it just parses xml as i've seen,do you know of
any that constructs or transforms xml ?
This is a simple XML reader/writer (though I've only used it for
reading) it''s free and the author is open to suggestions for fixes/
new features, very easy to use. http://www.applied-mathematics.net/tools/xmlParser.html
On Wed, 14 Feb 2007 04:17:15 -0800, steven acer wrote:
[...]
>C++ does not specify how the file is found. That depends on your compiler. Consult your compiler docs.
i did . i'm usig g++ for windows.it says to use the -
I<include_files_diretoryoption while compiling.
but it did not work !
it just could not find the files
i have in my header file
#include <xerces/dom/DOM.hpp>
on the command line typing : -Ic:\includes as an option for g++ never
works though the hierarchy xerces\dom\DOM.hpp is in c:\includes.
Maybe try specifying -Ic:/includes (with forward slash); I think g++ may
be happier with Unix-style paths.
im starting to think i need an IDE for this small task.
I suspect that might end up making your small task much larger...
--
Lionel B
steven acer wrote:
>>I though xerces did that too.
can you please show me a small example of writing xml to a file.
The sample called CreateDOMDocument seems to do what you require. http://xml.apache.org/xerces-c/samples.html
There's an alternative to Xerces on this site, claims to be smaller and
simpler than Xerces. http://www.applied-mathematics.net/
No recommendation here, I haven't used EITHER of these products.
john This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: William Krick |
last post by:
I've been given the task of converting some existing java code to PHP
so we can integrate it into our web based product.
The problem I'm facing is that the java code makes heavy use of Vector...
|
by: nanookfan |
last post by:
Hi all,
I'm having a bizarre problem converting XML files to HTML using an
XSLT. The problem is only occuring in my Netscape 7.0 browser. What
makes it more bizarre is that it is only...
|
by: Chad Z. Hower aka Kudzu |
last post by:
A few of you may recognize me from the recent posts I have made about Indy
<http://www.indyproject.org/indy.html>
Those of you coming to .net from the Delphi world know truly how unique and...
|
by: Elhanan Maayan |
last post by:
hi..
so i'm slowly moving the transition to csharp and once again i'm faced
with the problem for flipped hebew letters etc...
but now the problem may not be so hard to solve as i have seen...
|
by: singlal |
last post by:
Hi,
We are looking for options of converting CICS screens to a GUI
application (.net, Java, etc.) to increase the usability of the
screens. We would like to keep the underlying logic and...
|
by: anupamjain |
last post by:
Hi,
After 2 weeks of search/hit-and-trial I finally thought to revert to
the group to find solution to my problem.(something I should have done
much earlier)
This is the deal :
On a JSP...
|
by: helpwithcode |
last post by:
Hi people,
I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements,
String string_dob=text_dob.getText();
//Converting string to...
|
by: sriniwas |
last post by:
Hi Frnd's,
m using prefuse visulation,it's have one display class and this class have one saveImage(outPutStream, String jpg,double size);. now graph is converting ia jpg image properly.now my...
|
by: icanhelp33 |
last post by:
whats the best way for converting vb.net application to C#
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |