how to pass xml schema through sockets?
Could someone please help and tell me if there is a possibility to pass an xml schema thr开发者_如何学Pythonough a socket program written in C++ ? here is an example:
---- C++ ---- ...struct zone { // as an example
char *Var_name="xxx"; float var_value = 1.3; };----- xml ---
...<xs:element name="zone">
<xs:complexType>
<xs:sequence>
<xs:element name="Var_name" type="xs:string"/>
<xs:element name="var_value" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
------ C/C++ ----
... // send message to server if (send(csocket, buffer_snd, BUFSIZE, 0) > BUFSIZE) cout << send() failed << endl; ...Is this the way to exchange data as XML to avoid endianness when communicating between program running on Unix and other on Windows?
Thanking you in advance for your replies,
Anything that can be represented as a series of bytes can be sent via a socket. Since an XML schema is in textual form, it can be represented as a series of bytes. Hence, it can be sent via a socket.
And as additional information, not only must it be expressible as a series of bytes, it must also have some meaningful representation on the other end of the wire. Hence, a pointer to an object can be represented as a series of bytes, and you could send it over a socket, but it has no meaning when it's received by the receiver. An XML schema however, has meaning on either end, so it can be meaningfully sent over.
Edit:
std::string s;
s = "this is the static part of the string";
s += GetSomeStringFromSomewhere(); // This is a string that was dynamically retrieved
// And so on...
When you uploaded your question to SO, the sample schema was sent via a socket. When we viewed your question, it was sent via a socket again (and both transmissions appear to have succeeded).
Right now, it's apparent that the code you gave wasn't a direct copy and paste though, because it clearly won't compile exactly as-is. Our inability to see the real code you tried to use is a significant handicap in diagnosing any problems it may include.
精彩评论