|
KaptainKrayola
|
 |
« on: April 15, 2010, 02:39:39 PM » |
|
Ok, so I have this handy little chunk of XML i need to send to a remote server running Coldfusion. The CF server parses the XML and does stuff with it. I am setting a variable $xml = '[ chunk o' xml here ]'; then doing a cURL post to the remote server and all should be well. However, the remote server tells me An error occured while Parsing an XML document. Content is not allowed in prolog.
So to verify that the XML wasn't dorked up i ran it through "simplexml_load_string($xml);" which works fine and i can dump that out just fine so I'm assuming that means the XML is fine. Some google searches suggest that perhaps there is an invisible character before the beginning of the xml but some string parsing suggests otherwise. Has anyone had issues like this before and if so how did you solve it? PHP and some online xml validation tools both say the XML is fine but ColdFusion hates it. Ideas?
|
|
|
|
|
Logged
|
We can't stop here, this is bat country. 
|
|
|
|
perkiset
|
 |
« Reply #1 on: April 15, 2010, 02:41:12 PM » |
|
PM it.
|
|
|
|
|
Logged
|
It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
|
|
|
|
nutballs
|
 |
« Reply #2 on: April 15, 2010, 02:55:35 PM » |
|
yes it would be the invisible character issue for sure.
try removing all the whitespace outside the tags. so that all tags butt up against each other >< see if that helps.
Or its that you have some magic mac/utf/something character, like smart quotes.
|
|
|
|
|
Logged
|
I could eat a bowl of Alphabet Soup and shit a better argument than that.
|
|
|
|
KaptainKrayola
|
 |
« Reply #3 on: April 15, 2010, 03:01:28 PM » |
|
Perks - PM sent.
whatever it is trim() ignores it probably because its not whitespace or whatever. doing a substring to grab the first char gives me the first visible char.
really annoying.
i was thinking maybe some regex to strip everything that isn't visible but anytime i work with regex i need a drink so i haven't gotten that far yet.
|
|
|
|
|
Logged
|
We can't stop here, this is bat country. 
|
|
|
|
perkiset
|
 |
« Reply #4 on: April 15, 2010, 03:06:00 PM » |
|
trim only affects whitespace. I'm going to run it through a zapper and see if there's naughties in it.
But side note, I've had several times when XML validated but a particular parser hated it. We'll hopefully know soon...
|
|
|
|
|
Logged
|
It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
|
|
|
|
KaptainKrayola
|
 |
« Reply #5 on: April 15, 2010, 03:13:24 PM » |
|
trim only affects whitespace. I'm going to run it through a zapper and see if there's naughties in it.
But side note, I've had several times when XML validated but a particular parser hated it. We'll hopefully know soon...
you win the title of "favorite arizonian" for the day. where shall i send the prize?
|
|
|
|
|
Logged
|
We can't stop here, this is bat country. 
|
|
|
|
isthisthingon
|
 |
« Reply #6 on: April 15, 2010, 04:43:14 PM » |
|
you win the title of "favorite arizonian" for the day. where shall i send the prize? Apple1 Infinite Loop Cupertino, CA 95014 C/O Fanboi 
|
|
|
|
|
Logged
|
I would love to change the world, but they won't give me the source code.
|
|
|
|
Phaėton
|
 |
« Reply #7 on: April 16, 2010, 03:30:36 AM » |
|
you can use textwrangler for mac or pspad for windows in hex edit mode and see the hex display of the whole file to look for extra characters.....
|
|
|
|
Logged
|
When I was your age we used to walk to the TV to change the channel.... _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
|
|
|
|
Phaėton
|
 |
« Reply #8 on: April 17, 2010, 03:30:16 AM » |
|
trim only affects whitespace. I'm going to run it through a zapper and see if there's naughties in it.
But side note, I've had several times when XML validated but a particular parser hated it. We'll hopefully know soon...
Curious about this 'zapper' is it hand rolled?
|
|
|
|
|
Logged
|
When I was your age we used to walk to the TV to change the channel.... _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
|
|
|
|
perkiset
|
 |
« Reply #9 on: April 17, 2010, 09:19:18 AM » |
|
Nope ... BBEdit has a quick fix for just such a thing. It essentially is a string replace for anything none standard text and a CRLF normalizer. Could be done damn easily hand rolled actually.
|
|
|
|
|
Logged
|
It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
|
|
|
|
perkiset
|
 |
« Reply #10 on: April 19, 2010, 11:56:47 AM » |
|
Hey Kaptain - Couple things. First off, the cross between using PHP and then inline HTML and then back to PHP is really funky. I think what you're really trying to do should look like this: $myVar = <<<XML <request> ... blah blah ... </request> XML;
... rather than stopping the script and restarting it inline. Second, even though it validates, if I die out on the XML string you've created, the first < is missing - so it validates, but it's invalid. Totally weird. I think if you stuff the variable using the method I just described, then simply die("\n\n$xml\n\n") you'll see a difference and it should be OK. Ping me privately if you need to talk more on it... /p
|
|
|
|
|
Logged
|
It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
|
|
|
|
KaptainKrayola
|
 |
« Reply #11 on: April 19, 2010, 12:43:33 PM » |
|
ah ha! ok i'll give that a try. Thanks for checking that out for me Perks. i'll update with my findings 
|
|
|
|
|
Logged
|
We can't stop here, this is bat country. 
|
|
|
|
Phaėton
|
 |
« Reply #12 on: April 19, 2010, 03:35:48 PM » |
|
How would you write a parser like you mentioned above?
str_replace the non standard characters inside the tags?
normalize crlfs or encode them? do you mean #13#10 to #13
<xml><fieldone><fieldtwo><fieldtwo><fieldone>
How would you approach the xml normalizer validity checker ?
|
|
|
|
|
Logged
|
When I was your age we used to walk to the TV to change the channel.... _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
|
|
|
|
perkiset
|
 |
« Reply #13 on: April 19, 2010, 04:23:28 PM » |
|
Prolly I'd just do this: $newStr = preg_replace('/[^A-Z0-9\n\t !@#$%^&*()\-_[]{}|;:"\',<\.>\/\?\\]/i', '', $inStr);
Haven't checked that, just came out my fingers, but you get the idea
|
|
|
|
|
Logged
|
It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
|
|
|
|