Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manual XML encoding

Status
Not open for further replies.

jeskey

Programmer
May 3, 2005
7
US
I am new to xml. I wish to generate XML data from a SQL database to be returned to a Flash program. Although i have sample output as a guide, when i create the xml manually, it is not recognized as xml although it looks exactly like the sample output that does work correctly. I think it is also possible to have the database return xml so i do not have to hand encode it but i do not know how to do that either.

Below are two samples, one i manually created and one that is returned by an application. The first one is not recognized as xml, the second one is.

This is a sample of the output i created manually from a database:

<?xml version="1.0" encoding="iso-8859-1" ?>

<guestbook entries="1">
<entry>
<id>3</id>
<name>JASON KID</name>
<city>PHOENIX</city>
<state>AZ</state>

<comment></comment>
<datetime>3/18/2005 12:27:34 AM</datetime>
</entry>
</guestbook>

<?xml version="1.0" encoding="iso-8859-1" ?>

This is sample output i have that does work:

<guestbook entries="50">
<entry>
<id>12990</id>
<name>gy8hu8</name>
<emailaddress><![CDATA[]]></emailaddress>
<url><![CDATA[ijp]]></url>
<comments><![CDATA[ijp]]></comments>
<ipaddress>200.83.115.193</ipaddress>

<datetime>May 3, 2005, 12:17 AM UTC</datetime>
</entry>

Can anyone point me in the right direction?
 
Can you block your code in [code] blocks in the future...?

I can't tell if the examples are:
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<guestbook entries="1">
  <entry>
     <id>3</id>
     <name>JASON KID</name>
     <city>PHOENIX</city>
     <state>AZ</state>
     <comment></comment>
     <datetime>3/18/2005 12:27:34 AM</datetime>
  </entry>
</guestbook>
[b]<?xml version="1.0" encoding="iso-8859-1" ?>[/b]
and
Code:
<guestbook entries="50">
<entry>
    <id>12990</id>
    <name>gy8hu8</name>
    <emailaddress><![CDATA[]]></emailaddress>
    <url><![CDATA[ijp]]></url>
    <comments><![CDATA[ijp]]></comments>
    <ipaddress>200.83.115.193</ipaddress>
    <datetime>May 3, 2005, 12:17 AM UTC</datetime>
</entry>

-Or-
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<guestbook entries="1">
  <entry>
     <id>3</id>
     <name>JASON KID</name>
     <city>PHOENIX</city>
     <state>AZ</state>
     <comment></comment>
     <datetime>3/18/2005 12:27:34 AM</datetime>
  </entry>
</guestbook>
and
Code:
[b]<?xml version="1.0" encoding="iso-8859-1" ?>[/b]
<guestbook entries="50">
<entry>
    <id>12990</id>
    <name>gy8hu8</name>
    <emailaddress><![CDATA[]]></emailaddress>
    <url><![CDATA[ijp]]></url>
    <comments><![CDATA[ijp]]></comments>
    <ipaddress>200.83.115.193</ipaddress>
    <datetime>May 3, 2005, 12:17 AM UTC</datetime>
</entry>

Thus I have to assume that, if you are using the top set, It should look like this...
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<guestbook entries="1">
  <entry>
     <id>3</id>
     <name>JASON KID</name>
     <city>PHOENIX</city>
     <state>AZ</state>
     <comment />
     <datetime>3/18/2005 12:27:34 AM</datetime>
  </entry>
</guestbook>

Remove the second instance of:
<?xml version="1.0" encoding="iso-8859-1" ?>
at the bottom...
These are preprocessor tags which go before the xml, and do not require an end tag

and blank elements:
<comment></comment>
can have their tags combined into:
<comment />
(This is optional)

Also, the 2 sets of code contain different tags, which may cause problems if the target app is expecting specific tags...
Such as <comment> in the first and <comments> in the second.

If all else fails check your spelling... XML editors come in handy for this, as they typically highlight tags who's end tags cannot be matched...

Hope This Helps
Good Luck...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
The tag names are not important as i am just returning output to the browser at this point. The second XML statement was a cut and paste error, sorry.

I can tell that my output is not being coded correctly because the browser does not add "-" signs to the output indicating you can expand and contract the nodes.

The link of the working output is:

The link to the not working output is:

Also, I hate to be so ignorant, but how to you block code in this forum?

thanks
john
 
OH!!!...

the problem is you did not close the attribute:

<guestbook entries="10>

Code:
<?xml version="1.0" encoding="iso-8859-1" ?>

<guestbook entries="10[b][COLOR=red]"[/color][/b]>
<entry>
<id>14</id>
<name>KEVIN JACKSON</name>

Works fine now...

Hope this helps

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
This would probably be of great interest to you:

It is in beta state right now, so the download is free...

Be sure to read through this:

If you have a broadband connection, I strongly suggest giving it a try...

I've been using it for about 6 months or so now, and I'm addicted ;-)

I use it to create most of my XML files, and all XSLT...

It's great for javascript, and html also...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
I am sorry, I do not see what you mean. The entries value is closed in the output generated by the asp page mentioned above. You can go to the page and view source.

I am not sure what the new line character is for xml but i am beginning to think maybe that is the problem. I am using ASCII 13 (carrige return). I also tried the 13 & 10 combination.

I have made it so the asp page only list one entry from the database for easier reading.

Thanks,
John
 
OK...

When I click this link:

I get this:
Code:
The XML page cannot be displayed 
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. 


--------------------------------------------------------------------------------

The character '<' cannot be used in an attribute value. Error processing resource '[URL unfurl="true"]http://www.johneskey.com/gb_getdata.asp'...[/URL]

<entry>
^

It says that the attribute cannot contain the "<" character

If you view the source look carefully at the guestbook tag
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>

[b]<guestbook [COLOR=red]entries="1[/color]>[/b]
<entry>

Hope this helps...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Ok. I am confused, but you knew that already. I do appreciate your interest in helping me resolve this!!

When i go to the asp page, i get output to my browser (all on one line), the good link does not render the same way. I can then view the source of that output (look like it is formatted ok). Are you saying you cannot do that?

OR, are you using a tool (not a standard browser) that reports that error?

If i go to the asp page and then click view source, there appears to be no problem with the tags or the format.

I am sorry i do not understand this. Please do not assume i know anything.

Thanks,
john
 
I have figured out that my problem has to do with the characters i am concatenating between the tags when i build the string. If i open a properly formatted xml file and i cut and paste the ASCII characters from notepad into my document and resave it, it views properly.

Can someone tell me what characters are used in between tags ( line feeds) and for indenting (tabs).

thanks,
john
 
>>OR, are you using a tool (not a standard browser) that reports that error?

Internet Explorer

>>Can someone tell me what characters are used in between tags (line feeds) and for indenting (tabs).

White space is typically ignored by the XML parsers. CDATA might be an exception (?)

As far as between tags, they might as well be in one line...
The parser sees this:
Code:
<root>
  <parent>
    <child />
  </parent>
</root>
As:
Code:
<root><parent><child /></parent></root>

See the link above for info on Escapes (&lt; , &gt; ,...) and CDATA tags...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top