Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 17th, 2003, 05:38 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 451
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Ben Horne
Default XML Document Problem

Hi all,

So far, I've gotten a good start on my XML document. This is how it looks

<?xml version="1.0" encoding="utf-8"?>
<usa>
  <state>
    <stName>Wisconsin</stName>
    <stCapital>Madison</stCapital>
    <stPopulation>5,250,000</stPopulation>
    <stArea>65,503</stArea>
    <stCounties>
      <county>
        <coName>Dane</coName>
        <coSeat>Madison</coSeat>
        <coPopulation>430,000</coPopulation>
      </county>
      <county>
        <coName>Eau Claire</coName>
        <coSeat>Eau Claire City</coSeat>
        <coPopulation>94,219</coPopulation>
      </county>
    </stCounties>
  </state>
</usa>


The <state></state> tags are what's hanging me up. For every new state, do I have to include those tags? I tried doing so earlier and, although I was not getting any errors, I didn't think it was right due to the fact that even though, the other tags were collapsed, the tag for Florida was showing.

Ben
Madison Area Technical College student
-------------------------
I am one of those people that you call "Microsoft Access Freaks". I'm addicted to Access
__________________
Ben Horne
-------------------------
I don\'t want to sound like I haven\'t made any mistakes. I\'m confident I have.

Most likely using FireFox and concocting my next Macromedia Flash project
Snibworks Forums Moderator

Welcome to the New Age
 
Old November 17th, 2003, 06:01 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 451
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Ben Horne
Default

I've got it figured out. Now, I guess the only thing that I'll have trouble with is style sheets and the DTD file I've written. The DTD file is called usa.dtd. For the style sheets, I believe they have to be referenced (i.e. linked) from within the XML document. How can I do this?

Thanks in advance,



Ben
Madison Area Technical College student
-------------------------
I am one of those people that you call "Microsoft Access Freaks". I'm addicted to Access
 
Old November 17th, 2003, 06:09 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I go by this rule of thumb when I construct XML structures: If the item describes it's parent, it should be an attribute. If it can occur multiple times within the parent, then it needs to be a separate node. Here's how I would restructure the XML (If I were asked ;)):

<?xml version="1.0" encoding="utf-8"?>
<usa>
  <state name="Wisconsin" capital="Madison" population="5,250,000" area="65,503">
    <counties>
      <county name="Dane" seat="Madison" population="430,000" />
      <county name="Eau Claire" seat="Eau Claire" population="94,219" />
    </counties>
  </state>
</usa>

Within your XML document you add a xml-stylesheet node:

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="myXSLT.xslt" ?>
<rootXMLNode>
...
</rootXMLNode>


Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 17th, 2003, 06:19 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 451
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Ben Horne
Default

Hi Peter,

I have just one question regarding style sheets. Couldn't you include a reference to a CSS stylesheet in the XML file? I haven't gotten around to using XSLT in class yet. My initial thought when I read your reply was that using CSS would be easier for now until I got exposed to XSL.

Quote:
quote:Originally posted by planoie
 I go by this rule of thumb when I construct XML structures: If the item describes it's parent, it should be an attribute. If it can occur multiple times within the parent, then it needs to be a separate node. Here's how I would restructure the XML (If I were asked ;)):

<?xml version="1.0" encoding="utf-8"?>
<usa>
<state name="Wisconsin" capital="Madison" population="5,250,000" area="65,503">
    <counties>
     <county name="Dane" seat="Madison" population="430,000" />
     <county name="Eau Claire" seat="Eau Claire" population="94,219" />
    </counties>
</state>
</usa>

Within your XML document you add a xml-stylesheet node:

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="myXSLT.xslt" ?>
<rootXMLNode>
...
</rootXMLNode>


Peter
------------------------------------------------------
Work smarter, not harder.
Ben
Madison Area Technical College student
-------------------------
I am one of those people that you call "Microsoft Access Freaks". I'm addicted to Access
 
Old November 17th, 2003, 10:55 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Sorry, my apologies for missreading your original question about CSS. I jumped the gun.

Yes, you can reference a CSS...
From the Associating Style Sheets with XML documents W3C document:

<LINK href="mystyle.css" rel="style sheet" type="text/css">
<?xml-stylesheet href="mystyle.css" type="text/css"?>

<LINK href="mystyle.css" title="Compact" rel="stylesheet"
type="text/css">
<?xml-stylesheet href="mystyle.css" title="Compact" type="text/css"?>

<LINK href="mystyle.css" title="Medium" rel="alternate stylesheet"
type="text/css">
<?xml-stylesheet alternate="yes" href="mystyle.css" title="Medium"
type="text/css"?>

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 19th, 2003, 01:49 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 451
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Ben Horne
Default

Thanks for the help, Peter. I will keep the stuff about XSL in mind when I get around to it

Quote:
quote:Originally posted by planoie
 I go by this rule of thumb when I construct XML structures: If the item describes it's parent, it should be an attribute. If it can occur multiple times within the parent, then it needs to be a separate node. Here's how I would restructure the XML (If I were asked ;)):

<?xml version="1.0" encoding="utf-8"?>
<usa>
<state name="Wisconsin" capital="Madison" population="5,250,000" area="65,503">
    <counties>
     <county name="Dane" seat="Madison" population="430,000" />
     <county name="Eau Claire" seat="Eau Claire" population="94,219" />
    </counties>
</state>
</usa>

Within your XML document you add a xml-stylesheet node:

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="myXSLT.xslt" ?>
<rootXMLNode>
...
</rootXMLNode>


Peter
------------------------------------------------------
Work smarter, not harder.
Ben
Madison Area Technical College student
-------------------------
I am one of those people that you call "Microsoft Access Freaks". I'm addicted to Access





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Get XML Document from iFrame rvanandel Ajax 6 April 10th, 2009 05:24 AM
Problem in Coverting XML String into Document sheetm XML 5 April 27th, 2007 09:15 AM
Problem retrieving string value of XML document wslyhbb Javascript How-To 0 September 19th, 2006 08:16 AM
xml document androger XML 2 November 19th, 2003 05:52 PM
XML document "file name" schurli XSLT 5 August 30th, 2003 03:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.