Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    populate text within cdata from another xml

    plz help this is my code

    first xml - mainfood.xml

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE doc [
    <!ENTITY fooditems SYSTEM "foodnames.xml">
    ]>
    <content>
    
    <section name="pages">
    
    	<page name="food">
    	
    	<texts>
    
    <pageText> <![CDATA[
    <font face="arial">food</font>
    ]]></pageText>
    
    <pageText><![CDATA[
    &fooditems;
    ]]></pageText>
    
    
    </texts>
    		</page>	
    
    </section>
    
    
    </content>
    2nd xml - foodnames.xml

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <a >• <font face="Georgia">chicken biryani<br></a></font>
    <a >• <font face="Georgia">manchurian<br></a></font>
    <a >• <font face="Georgia">aloo dum<br></a></font>
    <a >• <font face="Georgia">sushi<br></a></font>
    basically i want tht lines like <a >• <font face="Georgia">chicken biryani<br></a></font> be read from foodnames.xml and popluated into mainfood.xml in place of &fooditems;

    but the code is not working....

    somene plz plz help

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,451
    Thanks
    17
    Thanked 275 Times in 275 Posts
    I don't write much XML but I pretty much think you will need javascript to do what you want. Both pages will reference the same .js file and it will take data from one and write data to the other one.

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    plz elaborate

  • #4
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    foodnames.xml is not well-formed XML for at least two reasons:
    (1) no root element
    (2) unclosed br tags

    Technically, mainfood.xml is not valid XML (there's a difference between "well-formed" and "valid") because the root element is content and the doctype says the root element should be doc. Also, your use of the <!ENTITY > tag is wrong as well... DrDOS is correct in pointing out you'll need some script to load foodnames.xml into memory (XMLHttpRequest comes to mind), parse it, and insert its contents into your mainfood.xml document.
    Last edited by Alex Vincent; 07-12-2012 at 01:55 AM.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #5
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,372
    Thanks
    32
    Thanked 286 Times in 280 Posts
    Quote Originally Posted by geniusmonster View Post
    but the code is not working....
    With regard to mainfood.xml: CDATA sections prevent all code—with the exception of the CDATA end delimiter—from being interpreted as markup. That includes entities. So, of course, the &fooditems; code will be interpreted as text (not an entity) and, therefore, not be replaced with your desired content. (Ditto for <font face="arial">food</font>.)

    With regard to foodnames.xml: As Alex Vincent indicated, this document is not a well-formed XML document. A well-formed XML document has a single root element that contains every other element in the document; your document has four root (a) elements). As he also indicated, all elements must be explicitly terminated; you have four unterminated br elements. Additionally, your document has four misnested tags; the font element end tags must appear before the a element end tags.

    All of that said, fixing these errors will not accomplish anything if your goal is to make your code work in mainstream browsers. I just tested six browsers using the following (correctly-written) code, and none of them support external entities:

    document.xhtml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html [
    	<!ENTITY external_entity SYSTEM "external_entity.xhtml">
    	<!ENTITY internal_entity "<span xmlns='http://www.w3.org/1999/xhtml' style='color: lime;'>Hello!</span>">
    ]>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
    	<head>
    		<title>Demo</title>
    		<style>
    			* { margin: 0; }
    			div { margin: 1em; }
    			p + p { padding: 1em; background-color: gray; color: white; }
    			em { font: inherit; font-weight: bold; }
    		</style>
    	</head>
    	<body>
    		<div>
    			<p>The lime‐colored text “Hello!” should appear in the following gray box if <em>external</em> entities are supported:</p>
    			<p>&external_entity;</p>
    		</div>
    		<div>
    			<p>The lime‐colored text “Hello!” should appear in the following gray box if <em>internal</em> entities are supported:</p>
    			<p>&internal_entity;</p>
    		</div>
    	</body>
    </html>
    external_entity.xhtml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <span xmlns="http://www.w3.org/1999/xhtml" style="color: lime;">Hello!</span>
    Quote Originally Posted by Alex Vincent View Post
    Also, your use of the <!ENTITY > tag is wrong as well...
    As far as I can tell, geniusmonster's ENTITY declaration is properly written per the XML 1.0 specification.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #6
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so does it mean it won't work...what i m trying to accomplish won't be achieved?

  • #7
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,372
    Thanks
    32
    Thanked 286 Times in 280 Posts
    Quote Originally Posted by geniusmonster View Post
    so does it mean it won't work...what i m trying to accomplish won't be achieved?
    Yes. It won't work. You can't use external entities to import information on the Web because browsers don't support them.

    If you need to import information, do it with a script (in the browser or on the server).
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #8
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how? plz guide as i m totally noobie i messed up my sister's work and have to get it sorted and i donno a from b in xml

  • #9
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    External entity declarations are supposed to point to DTD files, not other XML files, Arbitrator.

    geniusmonster: I really think you might be in over your head, using XML for a very simple purpose. You very well may want to rethink your approach to this entire problem - PHP, for example, might be able to generate a combined HTML document. Ask yourself what the overall goal is, and if XML really helps you get there.

    XML is most definitely not for people new to web design.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #10
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Alex Vincent View Post
    External entity declarations are supposed to point to DTD files, not other XML files, Arbitrator.

    geniusmonster: I really think you might be in over your head, using XML for a very simple purpose. You very well may want to rethink your approach to this entire problem - PHP, for example, might be able to generate a combined HTML document. Ask yourself what the overall goal is, and if XML really helps you get there.

    XML is most definitely not for people new to web design.
    the only thing i know id code was in xml...connected to flash can i use php within xml to achieve this goal?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •