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.

Similar Messages

  • Getting error "Cannot create a BACPAC from a file that does not contain exported data." from SqlManagementClient.Dac.ImportAsync

    We're trying to import a dacpac to azure via the new SqlManagementClient DacOperations ImportAsync api I get an exception with the error: "Cannot create a BACPAC from a file that does not contain exported data."
    This same dacpac imports fine using an alternate but less friendly API from sql server's tooling. We'd like to use the new management SDK instead for various reasons.

    Hi Kyle A Wilt,
    I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated.
    Thank you for your understanding and support.
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Xcode is running from a volume that does not support ownership. Please move Xcode to one that does.

    I have Problem,  I can't install Xcode 6.1 on my iMac due "Xcode is running from a volume that does not support ownership. Please move Xcode to one that does."
    I have two HD partition, First one I use for my Lion OS, and the second I just installed Yosemite since Xcode 6.1 need OS upper than lion.
    Here's my HD Info.
    Mac HD : Yosemite
    Machintosh HD: Lion
    I do try to uncheck and check when I install Xcode. Maybe I don't know where should I put Xcode.dmg when I want to install.
    Thank you. Sorry bad english.

    Run Disk Utility select the volume you are installing Xcode on and look at the bottom of the screen and make sure Owners Enabled: says yes.
    Also make sure there are no other versions of Xcode anywhere on your system. If there are delete them all and then do a fresh download and install of Xcode, BTW why are you nor installing from the Mac App Store, where did you get the dmg from?
    post back if that does not resolve the issue.
    regards

  • I need to get some video files onto my iphone from a computer that does not have my itunes library on it

    Currently I am away from home, and using a computer that does not have my main itunes library on it. I do, however, have some video files on this computer that I would like to place onto my phone for the drive home tomorrow. Unfortunately,  It seems there is no way to do this without completely wiping my iPhone and replacing it with this computers empty library, as the "manage content manually" feature apparently requires me to do this. Is there any way to just add some mp4s to my iphone without erasing all of its data?.

    ManSinha wrote:
    What kind of computer?
    On a Windows PC plugging in your phone will invoke the Autoplay dialog which also gives some options
    But only if iTunes is installed on the computer and is paired as a trusted device. Which the OP does not want to do.

  • Clean up old SID values from an InfoObject that does NOT have master data

    I have a characteristic infoobject that does NOT have Master Data but it has a SID table. I assume that it is used primarily for the F4 value help. Now we have changed some of our data for this infoobject in R3 so that some of the values in the SID table will never be used again. My problem is that these values are still displayed in the F4 value help. And because the old values are very similar to the new values some users mistakenly pick the old value and then the query results come back empty.
    FYI - The datasource that uses this infoobject as an attribute is extracted from R3 in a Full load each night. So there is no risk that the old values in the SID table will be needed in any Master Data/Cubes/DSOs/etc.
    Is there a way to delete the unwanted SIDs from this table /BIC/SXCSAOFREG? Or is there some way to make sure that the unwanted SIDs to not show up in the F4 value help?
    Thanks,
    Dave

    Hi David,
    Goto SE14 trans --> ENter the table name as  /BIC/SXCSAOFREG. Select the "Edit" radio button. Then Select "Delete Data" radion button & click on "Activate & adjust database". But be very careful NOT to click on Delete Database table(This will delete the physical database table!!!
    Regards,
    Pavan

  • HT4915 How do I delete unwanted music from an iPad that does not show in iTunes on the computer?

    How do I delete songs from my iPad that is not in my iTunes library on my laptop?  The songs appear to be from iCloud, but I don't sync to the cloud.  I sync to my laptop.  I am not using "Match".
    Mick

    Welcome to the Apple Community.
    Settings > Music > Show all music > Off

  • How do I delete unwanted music from an iPad that does not show in iTunes on the computer?

    How do I delete songs from my iPad that is not in my iTunes library on my laptop?  The songs appear to be from iCloud.  I sync to my laptop.  Show All music is off.  iTunes Match is off.

    Welcome to the Apple Community.
    Settings > Music > Show all music > Off

  • SKYPE INSTANT MESSENGER FROM AN ANDROID THAT DOES NOT HAVE THE SKYPE APP

    I HAVE A LENOVO HARD-WIRED TOWER & WINDOWS 8.1 OPERATING SYSTEM. MY FRIEND, DAVE, HAS AN ANDROID PHONE - HIS PHONE DOES NOT HAVE SKYPE INSTANT MESSENGER, BUT ANOTHER INSTANT MESSENGER THAT SHOWS A LIGHTNING BOLT. DAVE IS ONE OF MY SKYPE CONTACTS. WHEN I SEND DAVE MESSAGES VIA SKYPE INSTANT MESSENGER, HE CAN SEE MY MESSAGES, BUT I CAN NOT SEE HIS. ANY SUGGESTIONS, ADVICE? THANK YOU. SIGNED, GINA

    Hi! The obvious solution to this would be having your friend download skype from google play store. that way you're both on Skype, and it's free aswell. https://play.google.com/store/apps/details?id=com.skype.raider  

  • How do I print from a printer that does not support airprint?

    I have an ipad and would like to print photographs and e-mails from it via my Lexmark Pro901 wireless printer which does not seem to support Airprint,   Can anyone help please?

    Lexmark has an app I believe.
    Or you can look into third party apps. I use Print n Share, but i also see print central and printopia recommended

  • I cannot connect to the login page of my banking websites for Firefox but can from IE also firefox does not close when I shut it down I have just done a clean instal of windowsws7 and teh problem persists on reinstall of FF3.6.13

    I can connect with my banking websites but the login page will not come up. This is a recent occurrence and I have done virus scans and have also recently done a clean instal of Windows 7. The problem persists. I can connect to any other website with no problems. When I close FF it appears to close and Task manager shows as not running but it will not reopen. If I attempt to uninstall I am told that FF is running and needs to be closed. I have to reboot to get to close and be able to reopen.
    I can connect to the bank sites with IE. However I really don't like IE.
    I am using Win7 Professional on a Sony notebook VGN SZ55

    I don't have an answer, but I experienced the same problems trying to set up an airport express to route traffic to my stereo.
    Apple Extreme router, iMac and laptop all worked just fine for months, upon installing Airport Express (step by step, according to instructions), all **** broke loose. Airport Utility was unable to see my Airport Extreme router, after hours of rebooting computer, cable modem, router, and finally a hard reset of the Airport Extreme router, it is finally recognized by Airport Utility again.
    Recreated network, iMac connects to the internet just fine, laptop (Macbook Air) connects to the network just fine, but will not connect to the internet. Network diagnostics does not help, it gets to the "do you have a router? If so, reboot" stage, and never seems to see the router.
    Any suggestions?

  • Process that does not close and consumes 50% of CPU

    I have Windows 7, x86 and Reader v 11.0.5
    The issue is that when i close the application after viewing a file, the process "AcroRd32.exe" (actually there are two with the same name) take the CPU to 50%
    Here is a screenshot
    I took it after closing reader

    Hi MS_DC_1,
    Please try repairing Acrobat and check. Is this reproducible on other machines in your environment or is it machine speciifc.

  • Parsing xml from a socket stream

    Hi,
    I'm working on a client/server program, and I have the following problem. I'd like the client to send an xml-string to the server, and then the server to parse it (using SAX). The problem is, I cannot get the server to work.
    I thought the following would work, but it doesn't:
    InputSource xmlIn = new InputSource(socket.getInputStream());
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser xmlReader = factory.newSAXParser();     
    DefaultHandler handler = new MyHandler(); //          
    xmlReader.parse(xmlIn, handler);
    The setup now is, that the user of the client program can type something in the command line, press enter and the string is then sent to the server, which should parse it, but doesn't (instead gives a nullpointer exc.)
    Does anybody know how to parse an incoming string like this?
    thnx in advance,
    KS

    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.

  • How can I get a refund from another country that does not have an Apple Store?

    While going to the US for the summer, I went to the San Francisco Apple Store.
    I saw the Apple Gift Cards, and I was wondering if they would work on my Taiwan Apple ID, so I bought a $25 gift card and a 4 cards bundle pack each with $10 inside.
    But then now, coming back to Taiwan, I realised the gift cards was only valid for US users so I asked for support from Apple
    and this is what they replied:
    I understand that you are unable to redeem the gift card to your account, the card purchased in another country. I know you must be eager to get this issue resolved at the earliest. I can do my best to help you.
    Jonathan, I'm sorry to inform you that, iTunes Gift Cards are only redeemable in the iTunes Store for the country that is listed on the back of the card. I apologize for any inconvenience this may cause.
    This did not help me at all...
    There is only resellers in Taiwan, so there is no way I could get a refund from Taiwan
    so what should I do in order to get my money back?
    Or in other ways, an exchange upon other Apple products?

    I have now got an openoffice which I got from the internet. But the main thing is I paid £20.99 for this app and It is irriatting that the people who work for apple havent got back to me when I first reported a problem. I reported to them again and hoping that they will eventually get back to me.

  • Please help regarding registration re visa from a country that does not have postcodes for it will not register for visa card

    Need advice to register visa account on apple from Ireland which has no postcodes. It keeps looking for one and even tried to fake one. Am no techno on this thing that will get launched at the wall if I can not get to use it. Mercy please

    You have posted this in the forums dedicated to the iPad. Are you asking about some account associated with an iPad?
    Apple Stores, whether the iTunes Store, the Mac App Store or even Apple Store online require that you provide a bank card for the country that the Store is for. The bank card must also have a billing address in that country as well.
    So perhaps you are in the wrong Store. You need to be in the store for Ireland to use a bank card from Ireland. Go to the bottom of the page of the store you are in and look for the little circular flag icon. If it is not the Irish flag, then you need to change to the Irish store by clicking on the flag and selecting the correct country.

  • Xml from a php file does not load

    hi
    i have a php file that output an xml ,in order to use it in
    flash.
    when i test the php file in the browser i get the xml i need
    but in flash i get this error message:
    TypeError: Error #1088: The markup in the document following
    the root element must be well-formed.
    at taakexml_fla::MainTimeline/seexml()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()
    i took the xml i get and made it a separate file (an xml one)
    and i can load it.
    what am i doing wrong?
    best regards
    ron

    Try this php file:
    $xml_output .= "<posts>";
    while($row=mysql_fetch_array($Result)){
    $xml_output .= "<post>";
    $xml_output .=
    "<title>".$row['title']."</title>";
    $xml_output .= "<date>".$row['date']."</date>";
    $xml_output .=
    "<shortdesc>".$row['short_desc']."</shortdesc>";
    $xml_output .=
    "<thepost>".$row['thepost']."</thepost>";
    $xml_output .= "</post>";
    $xml_output .= "</posts>";
    echo $xml_output;
    Flash should do the rest.

Maybe you are looking for