The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 17, 2019, 06:36:06 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: XML woes  (Read 3348 times)
KaptainKrayola
Keeper of Pie
Global Moderator
Lifer
*****
Offline Offline

Posts: 994



View Profile WWW
« 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

Quote
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
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« 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
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« 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
Keeper of Pie
Global Moderator
Lifer
*****
Offline Offline

Posts: 994



View Profile WWW
« 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
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« 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
Keeper of Pie
Global Moderator
Lifer
*****
Offline Offline

Posts: 994



View Profile WWW
« 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
Global Moderator
Lifer
*****
Offline Offline

Posts: 2879



View Profile
« 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?

Apple
1 Infinite Loop
Cupertino, CA 95014
C/O Fanboi

 ROFLMAO
Logged

I would love to change the world, but they won't give me the source code.
Phaėton
Lifer
*****
Offline Offline

Posts: 555


⎝⏠⏝⏠⎠


View Profile
« 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.....



* hexeditmode.PNG (28.31 KB, 508x393 - viewed 218 times.)
Logged

When I was your age we used to walk to the TV to change the channel....  _̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡
Phaėton
Lifer
*****
Offline Offline

Posts: 555


⎝⏠⏝⏠⎠


View Profile
« 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
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« 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
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« 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
Keeper of Pie
Global Moderator
Lifer
*****
Offline Offline

Posts: 994



View Profile WWW
« 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  Grin
Logged

We can't stop here, this is bat country.
Phaėton
Lifer
*****
Offline Offline

Posts: 555


⎝⏠⏝⏠⎠


View Profile
« 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
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« 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.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!