Parse XML from std::wstring with XmlLite error: 0xc00cee04
Hello,
I am trying to parse the following XML (std::wstring) <message locale="en" log="true" data="'كيف حالك الآن؟">How do you do today?</message> but I get an 0xc00cee04 while reading the node type. Most probably I am not
passing the string content to the stream properly. Here s the code snippet:
CComPtr<IStream> stream;
std::shared_ptr<IXmlReader> reader;
HRESULT hr = S_OK;
COM_VERIFY(CreateStreamOnHGlobal(nullptr, false, (LPSTREAM*)&stream), L"CreateStream");
// Write message content into the stream
SIZE_T cbWrite;
COM_VERIFY(stream->Write(message.data(), message.size(), &cbWrite), L"WriteBuffer");
// Move to the beginning of the stream
LARGE_INTEGER position;
position.QuadPart = 0;
COM_VERIFY(stream->Seek(position, STREAM_SEEK_SET, nullptr), L"SeekPosition");
COM_VERIFY(CreateXmlReader(__uuidof(IXmlReader), (void**)&reader, nullptr), L"CreateXmlReader");
COM_VERIFY(reader->SetInput(stream), L"SetInputStream");
XmlNodeType nodeType;
while (!reader->IsEOF())
hr = reader->Read(&nodeType);
if (hr != S_OK) break; // <<< Here the error 0xc00cee04
What is the proper way to pass a wstring to IStream?
Thanks,
Pedro
On 4/18/2015 4:02 PM, MsdnDev wrote:
CComPtr<IStream> stream;
std::shared_ptr<IXmlReader> reader;
This makes no sense. shared_ptr will try to delete the pointer, but the COM pointer should be Release'd. You know enough to use CComPtr for IStream - how come you didn't do the same with IXmlReader?
// Write message content into the stream
SIZE_T cbWrite;
COM_VERIFY(stream->Write(message.data(), message.size(), &cbWrite), L"WriteBuffer");
What type is "message"? Is it wstring? If so, message.size() is the size in characters, but IStream::Write expects the size in bytes. You are only writing half the string.
Igor Tandetnik
Similar Messages
-
Parsing XML from Socket input stream
I create a sax parser to which I send the InputStream from the socket
But my HandlerBase never gets the events. I get startDocument
but that is it, I never get any other event.
The code I have works just like expected when I make the InputStream
come from a file. The only differeence I see is that when I file is used the
InputStream is fully consumed while with the socket the InputStream
is kept open (I MUST KEEP THE SOCKET OPEN ALL THE TIME). If the parser
does not generate the events unless the InputStream is fully consumed,
isn't that against the whole idea of SAX (sax event driven) .
Has anyone been succesfull parsing XML from the InputStream of a socket?
if yes how?
I am using JAXP 1.0.1 but I can upgrade to JAXP 1.1.0
which uses SAX 2.0
Does anybody know if my needs can be met by JAXP 1.1.0?
ThanksI did the same with client/server model.
I have client program with SAX parser. Please try if you can make the server side. I was be able to write the program with help from this forum. Please search to see if you can get the forum from which I got help for this program.
// JAXP packages
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
// JAVA packages
import java.util.*;
import java.io.*;
import java.net.*;
public class XMLSocketClient {
final private static int buffSize = 1024*10;
final private static int PORTNUM = 8888;
final private static int threadSleepValue = 1000;
private static void usage() {
System.err.println("Usage: XMLSocketClient [-v] serverAddr");
System.err.println(" -v = validation");
System.exit(1);
public static void main(String[] args) {
String address = null;
boolean validation = false;
Socket socket = null;
InputStreamReader isr_socket = null;
BufferedReader br_socket = null;
CharArrayReader car = null;
BufferedReader br_car = null;
char[] charBuff = new char[buffSize];
int in_buff = 0;
* Parse arguments of command options
for (int i = 0; i < args.length; i++) {
if (args.equals("-v")) {
validation = true;
} else {
address = args[i];
// Must be last arg
if (i != args.length - 1) {
usage();
// Initialize the socket and streams
try {
socket = new Socket(address, PORTNUM);
isr_socket = new InputStreamReader(socket.getInputStream());
br_socket = new BufferedReader(isr_socket, buffSize);
catch (IOException e) {
System.err.println("Exception: couldn't create stream socket "
+ e.getMessage());
System.exit(1);
* Check whether the buffer has input.
try {
while (br_socket.ready() != true) {
try {
Thread.currentThread().sleep(threadSleepValue);
catch (InterruptedException ie) {
System.err.println("Interrupted error for sleep: "+ ie.getMessage());
System.exit(1);
catch (IOException e) {
System.err.println("I/O error for in.read(): "+ e.getMessage());
System.exit(1);
try {
in_buff = br_socket.read(charBuff, 0, buffSize);
System.out.println("in_buff = " + in_buff);
System.out.println("charBuff length: " + charBuff.length);
if (in_buff != -1) {
System.out.println("End of file");
} catch (IOException e) {
System.out.println("Exception: " + e.getMessage());
System.exit(1);
System.out.println("reading XML file:");
StringBuffer display = new StringBuffer();
display.append(charBuff, 0, in_buff);
System.out.println(display.toString());
* Create BufferedReader from the charBuff
* in order to put into XML parser.
car = new CharArrayReader(charBuff, 0, in_buff); // these two lines have to be here.
br_car = new BufferedReader(car);
* Create a JAXP SAXParserFactory and configure it
* This section is standard handling of XML document by SAX XML parser.
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(validation);
XMLReader xmlReader = null;
try {
// Create a JAXP SAXParser
SAXParser saxParser = spf.newSAXParser();
// Get the encapsulated SAX XMLReader
xmlReader = saxParser.getXMLReader();
} catch (Exception ex) {
System.err.println(ex);
System.exit(1);
// Set the ContentHandler of the XMLReader
xmlReader.setContentHandler(new MyXMLHandler());
// Set an ErrorHandler before parsing
xmlReader.setErrorHandler(new MyErrorHandler(System.err));
try {
* Tell the XMLReader to parse the XML document
xmlReader.parse(new InputSource(br_car));
} catch (SAXException se) {
System.err.println(se.getMessage());
System.exit(1);
} catch (IOException ioe) {
System.err.println(ioe);
System.exit(1);
* Clearance of i/o functions after parsing.
try {
br_socket.close();
} catch (IOException e) {
System.out.println("Exception: " + e.getMessage());
try {
socket.close();
} catch (IOException e) {
System.out.println("Exception: " + e.getMessage());
try {
br_car.close();
} catch (IOException e) {
System.out.println("Exception: " + e.getMessage());
* The XML handler used by this program
class MyXMLHandler extends DefaultHandler {
// A Hashtable with tag names as keys and Integers as values
private Hashtable tags;
// Parser calls this once at the beginning of a document
public void startDocument() throws SAXException {
System.out.println("startDocument()");
tags = new Hashtable();
// Parser calls this for each element in a document
public void startElement(String namespaceURI, String localName,
String rawName, Attributes atts)
throws SAXException
String key = localName;
Object value = tags.get(key);
System.out.println("startElement()");
System.out.println("namespaceURI: " + namespaceURI);
System.out.println("localName: " + localName);
System.out.println("rawName: " + rawName);
if (value == null) {
// Add a new entry
tags.put(key, new Integer(1));
} else {
// Get the current count and increment it
int count = ((Integer)value).intValue();
count++;
tags.put(key, new Integer(count));
// Parser calls this once after parsing a document
public void endDocument() throws SAXException {
Enumeration e = tags.keys();
System.out.println("endDocument()");
while (e.hasMoreElements()) {
String tag = (String)e.nextElement();
int count = ((Integer)tags.get(tag)).intValue();
System.out.println("Tag <" + tag + "> occurs " + count
+ " times");
* Error handler of XML parser to report errors and warnings
* This is standard handling.
class MyErrorHandler implements ErrorHandler {
/** Error handler output goes here */
private PrintStream out;
MyErrorHandler(PrintStream out) {
this.out = out;
* Returns a string describing parse exception details
private String getParseExceptionInfo(SAXParseException spe) {
String systemId = spe.getSystemId();
if (systemId == null) {
systemId = "null";
String info = "URI=" + systemId +
" Line=" + spe.getLineNumber() +
": " + spe.getMessage();
return info;
* The following methods are standard SAX ErrorHandler methods.
* See SAX documentation for more info.
public void warning(SAXParseException spe) throws SAXException {
out.println("Warning: " + getParseExceptionInfo(spe));
public void error(SAXParseException spe) throws SAXException {
String message = "Error: " + getParseExceptionInfo(spe);
throw new SAXException(message);
public void fatalError(SAXParseException spe) throws SAXException {
String message = "Fatal Error: " + getParseExceptionInfo(spe);
throw new SAXException(message); -
Can't parse xml from applet using dom on linux on Netscape 7 using jre 1.4.
Hi,
I can't seem to parse xml from an applet on linux on Netscape 7 using the JRE 1.4.
My code looks like the following:
StringBufferInputStream is = new StringBufferInputStream("<foo></foo>");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try
builder = factory.newDocumentBuilder();
domDocument = builder.parse(is); // this line creates an exception
catch (Exception e)
System.out.println(e);
This code works fine from an applet on windows. On linux, the error message is:
java.security.AccessControlException: access denied (java.util.PropertyPermission entityExpansionLimit read)
I've tried both JRE 1.4.0_04 and 1.4.1_03
Thanks!
QThere's another posting about this same problem (platform unspecified), but the same error message. I was also having this problem (Windows 1.4.03) and swithced back to 1.4.01 and the problem went away. In the future, I may sign my applets to get a more generous security policy. But, I'm sure it'll be a lot of work (vs. a line of code somewhere).
-
Xerces - Parse XML from String
I am trying to parse an xml string using Xerces.
I have the following code:
String xml = <segments meters="8643" seconds="538" distance="5.4 mi" time="8 mins"><segment id="seg0" pointIndex="0" meters="122" seconds="11" distance="0.1 mi" time="11 secs">Head <b>southwest</b> from <b>B Ave NE</b>
</segment>
<segment id="seg1" pointIndex="2" meters="239" seconds="22" distance="0.1 mi" time="21 secs">Turn <b>left</b> at <b>19th St NE</b></segment>
<segment id="seg2" pointIndex="5" meters="2985" seconds="192" distance="1.9 mi" time="3 mins">Turn <b>right</b> at <b>1st Ave NE</b></segment>
<segment id="seg3" pointIndex="43" meters="3280" seconds="211" distance="2.0 mi" time="3 mins">Continue on <b>1st Ave SW/1st Ave NW</b></segment>
<segment id="seg4" pointIndex="96" meters="158" seconds="10" distance="0.1 mi" time="10 secs">Bear <b>right</b> at <b>US-151-BR S</b></segment>
<segment id="seg5" pointIndex="102" meters="1859" seconds="93" distance="1.2 mi" time="1 min">Turn <b>right</b> at <b>16th Ave SW</b></segment>;
XMLReader reader = new SAXParser();
reader.setContentHandler(new Handler());
reader.parse(xml);I am getting the followoing error:
org.xml.sax.SAXParseException: File "<segments meters="8643" seconds="538" distance="5.4 mi" time="8 mins"><segment id="seg0" pointIndex="0" meters="122" seconds="11" distance="0.1 mi" time="11 secs">Head <b>southwest</b> from <b>B Ave NE</b></segment><segment id="seg1" pointIndex="2" meters="239" seconds="22" distance="0.1 mi" time="21 secs">Turn <b>left</b> at <b>19th St NE</b></segment><segment id="seg2" pointIndex="5" meters="2985" seconds="192" distance="1.9 mi" time="3 mins">Turn <b>right</b> at <b>1st Ave NE</b></segment><segment id="seg3" pointIndex="43" meters="3280" seconds="211" distance="2.0 mi" time="3 mins">Continue on <b>1st Ave SW/1st Ave NW</b></segment><segment id="seg4" pointIndex="96" meters="158" seconds="10" distance="0.1 mi" time="10 secs">Bear <b>right</b> at <b>US-151-BR S</b></segment><segment id="seg5" pointIndex="102" meters="1859" seconds="93" distance="1.2 mi" time="1 min">Turn <b>right</b> at <b>16th Ave SW</b></segment></segments>" not found.
at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1219)
at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromDocument(DefaultEntityHandler.java:501)
at org.apache.xerces.framework.XMLParser.parseSomeSetup(XMLParser.java:314)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1097)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1139)
at com.shiftyeyes.xmlTest.main(xmlTest.java:34)
Exception in thread "main" anyone know how I can fix this? Thanks!!reader.parse(new InputSource(new StringReader(xml)));
-
How can I parse XML from CLOB field? I need to replace or delete the node from XML document and update the database with new XML. I am using Oracle 9i release 2.
Here is the XML. In this XML if section1 and section2 exists then I need to delete the section1 node. If section2 doesn't exist, replace section1 with section2 node.
<Document ID='2' TypeID='2'>
<Body>
<Page Name='Page1'>
<Sec ID='section1' Title='Section 1' GroupID='' />
<Sec ID='section2' Title='Section 2' GroupID='' />
</Page>
</Body>
</Document>
Please help.. Thank you..In 9.2, you are limited into your options. Have a look into, among others, updateXML. Updating tp 10gR2 will give you more options to succeed.
-
App runs in Eclipse environment but not from jar file with no error message
When I upgraded my jre to 5.0 my app does not run. After fixing the properties problem I had a few days ago it is now at least compiling and running within Eclpse
However, when I export to a jar file it runs to a certain point and then just goes away with no error message!!! I've narrowed it down to the exact point where it dies but don't understand why it dies and especially gives me no errors whatsoever. It just goes away.
It is creating an instance of a new class when it dies.
Can someone please help me?Ok, well it doesn't. Anyway, I'm still having the same problems. I can run my jar file to a certain point and then the application just stops. I know this because I've put come message boxes in the application to let me know where in the app the system is.
It always dies when it is instantiating the new class called HeidiFrame; done by:
HeidiFrame heidiFrame = null;
if I put code in between the above line and before the below line, this code will work fine
heidiFrame = new HeidiFrame();
but if I put code after the above line, nothing happens
As I said this all worked fine until I upgraded to Java 1.5
If you look at http://java.sun.com/javase/technologies/compatibility.jsp there are 23 compatibility issues with the new release. We're using xml stuff so that was my first problem and the code wouldn't even compiile. Once I added in libraries, the code compiled and ran beautifully.
However, when creating my jar file so I can deploy this application , I've discovered that the jar file will only run to a certain point, as I've stated previously. So, that's my problem. Not that I can't run it from the command prompt, which I can't, but it's a gui application. I've tried changing things in the classpath file and the manifest to no avail. Nothing changes. The application starts but when it goes to instantiate the HeidiFrame class, which is the class that actually builds the gui it dies and goes bye bye. -
Parsing XML from a session bean
Hi,
I am trying to use a Sax parser for parsing xml received from a back end
legacy system. The code is executed from a Session bean.
Debugging learned me that the parse() method on the parser hangs the
container without any error or exception trace. The code works fine outside
a container.
All help will be highly appreciated.
KurtI found out that the InputStream implementation used parsing source inside
the container is different
then from the one outside (other type of VM of course!). The Weblogic
implementation blocks at the end of
the stream, while the normal SUN JDK 1.3 returns. This is not a bug, the bug
I found is in my proxy that allows
the connection to the backend. This proxy allows HTTP connections, and I
parse the XML received over HTTP.
Regards,
Kurt
"Todd Karakashian" <[email protected]> wrote in message
news:[email protected]..
That's seems odd. Perhaps there is something going on in your document
handler code that triggers a hang in the environment of the server.
When you see the hang, instruct the VM to give you a thread dump (type
control-<break> on Windows, <control>-\ (backslash) on UNIX in the
window in which the server is running; the results are dumped to
stderr). That will show what every thread in the server is doing. If you
email or post the thread dump, I will take a look at it and see if I can
see what is going on. Also, let us know which platform, VM, parser, and
WebLogic version you are using.
Regards,
-Todd
Kurt Quirijnen wrote:
Hi,
I am trying to use a Sax parser for parsing xml received from a back end
legacy system. The code is executed from a Session bean.
Debugging learned me that the parse() method on the parser hangs the
container without any error or exception trace. The code works fine
outside
a container.
All help will be highly appreciated.
Kurt--
Todd Karakashian
BEA Systems, Inc.
[email protected] -
How to use DOMParser from an Applet / Or, how to parse XML from an Applet?
Hey,
As stating in the subject line, I wonder how to do it without getting an �Access Denied� error.
I would like to parse a XML file that has external DTD pointing to a SYSTEM location. Yes, I can change it to a public location. However, in either way, I have problems to use DOMBuilder to parse the xml file. The application always throws the security exception.
I tried to use the DOMParser from org.apache.xerces.parsers to parse the xml file. I set the DOMParser to ignore parsing the external DTD, and use the DOMParser.parse(InputSource) to parse the xml file from a giving URL. However, I get null of the result document.
Does anyone know how to parse the XML from an Applet? Or, does anyone know how to use the DOMParser from an Applet?
Thank you very much,If the document resides on the local filesystem, you will need to sign a CAB or JAR for the applet to circumvent the sandbox's security restrictions. There are dozens of posts on how to do this. Basically, that will turn the applet into an application, from a Java security perspective.
- Saish
"My karma ran over your dogma." - Anon -
Parsing xml from forms6i,can anyone please help me
Can anyone please help me.I need to parse a xml file from a directory.The parsing should help me in giving a structure for two things.
1) i should be able to read the nodes( values between the tags) and display the values at my front-end textboxex
2) whenever the user changes the front-end content it should change the corresponding value in the xml node.
when it is finished i should be able to save the structure back as a xml file.This file is actually a blob object in the oracle database and is it wise to convert it into a file in dos directory and parse it from there or use oracle utilities from form6i and parse it from oracle utilities.
Please if someone can find help on this ,it would really help me.No the password isn't your apple id password.
You encrypted your backup with a password, if you don't remember the password, then i'm sorry you won't be able to use it. -
I have Itunes set up to sync with my Ipod touch and Ipad. As of today, iTunes has started searching to sync with an iPhone, which I don't have and pops open with an error message stating it cannot locate the iPhone to sync. I have looked in devices and only the iPad and iPod Touch are listed. Any ideas on how to stop iTunes from searching for any iPhone it is never going to find? It is annoying to have it popping up all the time with the error message. Thanks in advance for any suggestions.
You should really read the manual.
"How do you restore from backup? "
Restore. When given the choice, choose to use backup.
"And how can I check to see if the pics and videos are on my computer somewhere first??"
They would only be where you put them. What program did you use to import them? Pics/vids taken with ipod are not part of the sync process at all. You should be importing them just as you would with any digital camera.
If you did not import them, then they are not on your computer. -
Large XML Publisher reports fail with client-error-request-value-too-long
We are running BI Publisher 5.6.3 with Oracle Applications 11.5.10.2 (ATG.H RUP 5), and are having frequent failures with client-error-request-value-too-long messages on large PDF reports that cause the entire report to not print.
The exact error message is as follows:
lp: unable to print file: client-error-request-value-too-long
Pasta: Error: Print failed. Command=lp -c -dPDX_B6_1LJ5200NEAST /logs/temp/pasta3262_0.tmp
Pasta: Error: Check printCommand/ntPrintCommand in pasta.cfg
Pasta: Error: Preprocess or Print command failed!!!
APP-FND-00500: AFPPRN received a return code of failure from routine FDUPRN. Program exited with status 1
Cause: AFPPRN received a return code of failure from the OSD routine FDUPRN. Program exited with status 1.
Action: Review your concurrent request log file for more detailed information.
I have Google'd client-error-request-value-too-long, and found it is a common CUPS issue on Linux. The popular solutions (having /var/spool/cups and /var/spool/cups/tmp) are already in place. Also, the temp files are nowhere near 2 GB (44MB).
Has anyone had this issue with BI Publisher on Linux?Thanks for the link. It looks like the sysadmins have throttled cups to low to allow large bitmapped print jobs:
grep MaxRequestSize cupsd.conf
# MaxRequestSize: controls the maximum size of HTTP requests and print files.
MaxRequestSize 10M
I am trying to get a more reasonable size limit. -
Urgent : Need help in parsing XML from Sharepoint and save it into DB
Hi ,
I am Sharepoint guy and a newbie in Oracle . PL/SQL
I am using UTL_DBWS Package to call a Sharepoint WebService " and was sucessfull , Now the xml has to be parsed and stored into a Table. I am facing the issue as the XML has a different namesoace and normal XPATH query is not working
Below is the XML and need help in parsing it
declare
responsexml sys.XMLTYPE;
testparsexml sys.XMLTYPE;
begin
responsexml := sys.XMLTYPE('<GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<GetListItemsResult>
<listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<rs:data ItemCount="2">
<z:row ows_MetaInfo="1;#" ows__ModerationStatus="0" ows__Level="1" ows_Title="Test Title 1" ows_ID="1" ows_owshiddenversion="1" ows_UniqueId="1;#{9C45D54E-150E-4509-B59A-DB5A1B97E034}" ows_FSObjType="1;#0" ows_Created="2009-09-12 17:13:16" ows_FileRef="1;#Lists/Tasks/1_.000"/>
<z:row ows_MetaInfo="2;#" ows__ModerationStatus="0" ows__Level="1" ows_Title="Testing Tasks" ows_ID="2" ows_owshiddenversion="1" ows_UniqueId="2;#{8942E211-460B-422A-B1AD-1347F062114A}" ows_FSObjType="2;#0" ows_Created="2010-02-14 16:44:40" ows_FileRef="2;#Lists/Tasks/2_.000"/>
</rs:data>
</listitems>
</GetListItemsResult>
</GetListItemsResponse>');
testparsexml := responsexml.extract('/GetListItemsResponse/GetListItemsResult/listitems/rs:data/z:row/@ows_Title');
DBMS_OUTPUT.PUT_LINE(testparsexml.extract('/').getstringval());
end;
The issue is with rs:data , z:row nodes.... please suggest how to handle these kind of namespaces in Oracle
I need the parse the attribute "ows_Title" and save it into a DB
this script would generate "Error occured in XML Parsing"
Help is appriciated, thanks for lookingSQL> SELECT *
FROM XMLTABLE (
xmlnamespaces ('http://schemas.microsoft.com/sharepoint/soap/' as "soap",
'#RowsetSchema' AS "z"
'for $i in //soap:*//z:row return $i'
PASSING xmltype (
'<GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<GetListItemsResult>
<listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<rs:data ItemCount="2">
<z:row ows_MetaInfo="1;#" ows__ModerationStatus="0" ows__Level="1" ows_Title="Test Title 1" ows_ID="1" ows_owshiddenversion="1" ows_UniqueId="1;#{9C45D54E-150E-4509-B59A-DB5A1B97E034}" ows_FSObjType="1;#0" ows_Created="2009-09-12 17:13:16" ows_FileRef="1;#Lists/Tasks/1_.000"/>
<z:row ows_MetaInfo="2;#" ows__ModerationStatus="0" ows__Level="1" ows_Title="Testing Tasks" ows_ID="2" ows_owshiddenversion="1" ows_UniqueId="2;#{8942E211-460B-422A-B1AD-1347F062114A}" ows_FSObjType="2;#0" ows_Created="2010-02-14 16:44:40" ows_FileRef="2;#Lists/Tasks/2_.000"/>
</rs:data>
</listitems>
</GetListItemsResult>
</GetListItemsResponse>')
columns ows_MetaInfo varchar2(20) path '@ows_MetaInfo',
ows_Title varchar2(20) path '@ows_Title',
ows__ModerationStatus varchar2(20) path '@ows__ModerationStatus'
OWS_METAINFO OWS_TITLE OWS__MODERATIONSTATUS
1;# Test Title 1 0
2;# Testing Tasks 0
2 rows selected. -
Parsing XML from a socket that does not close
Hi -
I've seen similar questions to this already posted, but either they did not really apply to my situation or they were not answered.
I have to read messages from a server and process them individually, but the protocol does not indicate the message length or give any sort of terminating character. You only know you have a complete message because it will be a well formed XML fragment. To complicate matters more, there could be extra binary data preceding each XML message. I must stress that I did not write this server, and I have no influence over the protocol at all, so while I certainly agree that this is not such a good protocol, changing it is not an option.
I'm hoping that there is a reasonable way to deal with this with an existing parser. Ironically, I don't really need to parse the XML at all, I just need to know when the current message is over but the only indication I get is that it will be the end of an XML fragment.
I do have the ability to strip off the non-XML binary data, so if there is some way that I can give the stream to a SAX (or other) parser when I know XML is coming and have it inform me when tags begin and end, or ideally inform me when it is done a complete XML fragment, that would be perfect. I'm aware of how to do this using SAX normally, but it seems that it will not function correctly when there is no EOF or other indication that the document has ended.
The best algorithm I have come up with (and it's pretty cheesy) is:
1. Start with a string buffer.
2. Append data from the socket to the buffer one byte at a time.
3. Keep checking if there is a '<' character that is not followed by '?' or '!'. (ie - don't concern myself with the special XML elements that don't close with '/>' or </tagName>. I keep them in the buffer to pass on when I'm done though.)
4. When I get my first tag with <tagName> I make note of what this tag is and increment a counter. If the tag is self closing, then I'm done.
5. Anytime I see this tag I increment the counter.
6. Anytime I see </tagName> I decrement the counter. If the counter = 0, I am done.
7. I pass on the entire message, preceding binary data, special XML tags and the fragment to the module that actually processes it.
This has a few problems. I'll have to go out of my way to support multiple character encodings, I'll have to be careful to catch all the special XML tags, and its quite CPU intensive to be interested in every single character that comes down the pipe (but I suppose this is not avoidable). Also, I just don't like to re-invent the wheel because I'm likely to make an error that a well established parser would not make.
Does anyone have any suggestions for this, or know of a parser that will deal with fragments using streams that don't close?
Thanks!The parser expects to read to the end of the stream. If you closed the stream right after you wrote to it, I bet it would work. You wouldn't want to close the stream though would you? Try sending the string using a DataOuputStream and calling DataOutputStream.writeUTF(String) on the client side. Then, on the server side call String str = in.readUTF() (where 'in' is a DataInputStream). Then wrap the string in a StringReader and give the StringReader to the parser as it's input source.
-
Parsing XML from ZipInputStream
I am reading a large XML file directly from a zipEntry. When I run this it appears to only send the parser one chunck of data. Once it parses that first read from my inputstream, it abend with an "empty String" error. I have been looking around the net for examples and it's starting to appear like I am the first person in the world to attempt this. Please Help!!!! I have included my code for anyone to look at.
ZipFile zf = new ZipFile(parsefile);
Enumeration zipEnum = zf.entries();
ZipEntry ze = (ZipEntry) zipEnum.nextElement();
System.out.println(ze.getName() + ", " +
ze.getCompressedSize() + ", " +
ze.getSize() );
seh = new SAXRptEventHandler();
xmlIn = new org.xml.sax.InputSource(zf.getInputStream(ze));
xmlIn.setSystemId("/tsyd/tsydmt2/data/ReportExtract.dtd");
XMLReader parser = (XMLReader)Class.forName
("org.apache.xerces.parsers.SAXParser").newInstance();
parser.setContentHandler(seh);
parser.setErrorHandler(seh);
parser.parse(xmlIn);
zf.close();I got the DTD working from watching other posts on here. I did use the entityResolver and it works perfect. I am having the similar problem that I've seen elsewhere in that my parser will just stop receiving data. My output file is always the same size. I am trying to figure out now if my input stream needs something else or if this might be a system problem. I never did see a resolution to other people who said their parser stops working when they use an inputstream.
any help or advice is always appreciated. -
I really hope that somebody can help me with this.....
I'm trying to simply parse an xml document into an applet so that the info can be used later on. I just need the tag, attribute and value.
So far, all that I can do is get the "access denied" java.util.propertypermission user.dir read error that I see tons of people complaining about. here's my code:
public StageInfo getNextStage() throws Exception
handler = new GameXMLHandler(m_imageGiver, m_codeBase);
spf = SAXParserFactory.newInstance();
parser = spf.newSAXParser();
parser.parse("Loader.xml", handler);
return handler.getStageInfo();
}is there a way to parse an xml file in an applet? everywhere I look, somebody is saying that it can be done, but never have they done it. I'm starting to think that there is something beyond my control that is stopping this from working. Please help!!!!If I read your post correctly, your applet is trying to read xml file from the user's local drive? This must be done with a signed (trusted) applet. Otherwise normal run-of-the-mill applets can't access drives. Java security feature. You can use Frame, it can access local drives.
Maybe you are looking for
-
In the bottom right corner of my screen there is this irregularly shaped patch of screen that is brighter than the rest. Around it is a "halo" of darker screen. Is there anyone else out there who has had this problem or knows how to fix it? Thanks
-
Mavericks Bootcamp! Should I use Windows 7 or 8? x64 or x86?
What version of Windows works best with Mavericks Bootcamp? Should I use Windows 7 or 8? x64 or x86?
-
Web form and database security risk
I'd like to develop an Oracle Form or APEX Form where people don't have to login to use it. Like a registration form on our website, where anyone can fill it out. Ideally, the information entered into the form would be saved to an Oracle table (could
-
TFS 2013 Upgrade 3 Admin Console hangs
Hi, I upgraded TFS 2013 to TFS 2013.3 and it worked ok for few days. Now when i try to access TFS Admin Console it hangs. When I try to access through TWA its d same problem. I did a)Recycle App pool b)Restart the TFS site c)Reboot the server yet I
-
Cannot find keychain to store safari
When i open Safari i get a dialogue box saying a keychain for saving "safari" cannot be found. I tried to use utility to repair but it would not work.