Jump to content

steve_marjoribanks

Members
  • Posts

    22
  • Joined

  • Last visited

Posts posted by steve_marjoribanks

  1. Hi, ive got the following task:Give the DTD for an XML representation of the following nested relational schema.Emp =(ename, ChildrenSet setof(Children), SkillsSet setof(Skills))Children =(name, Birthday)Birthday = (day, month, year)Skills = (type, ExamsSet setof(Exams))Exams = (year, city)I'm really lost on how to do this. Any help would be great. Ive read the tutorials. Just think i need some more help!Thanks!

    Homework question is it?! :) You really should be able to do that just after reading the tutorial.
  2. Well you're schema has a target namespace and your XML document is using a noNamespaceSchemaLocation attribute. The clue is in the name of the attribute. Try reading up on XML namespaces, it can be quite confusing!

  3. Your answer is no!XML Schemas are purely for validation purposes and cannot perform any sort of interactions with databases, applications or anything! You have to use a separate programming language which can be used along with XML to achieve this.

  4. Helloi am new with schema and facing many problems in it.Consider an a piece of xml file below<artist>Nusrat <lastname>Ali</lastname></artist>I want to restrict "Nusrat" in XML schema but not getting how?can anybody help me out?Best RegardsHuma

    I think you should strongly consider re-structuring your XML so it looks like this:<artist> <firstName>Nusrat</firstName> <lastName>Ali</lastName></artist>Using mixed content elements is not recommended for data storage of this kind.
  5. I have found that Firefox doesn't really like XSL stylesheets! Whenever I try to view an XML document with an associated XSL stylesheet in Firefox it *always* comes up with that error. This maybe something I am doing wrong, or I need to download a patch or something (in which case I would very much appreciate some input!).In answer to your question, just try it in Internet Explorer, I think it will probably work!

  6. I guess you're wanting the output to be in the form of a page in a web browser? If so, your stylesheet will be in html anyhow so can't you just put a <br/> in where you want the new line?

  7. You can but you would use them in this case as: <cd test2="test1:test">ie. specifying the namespace in the attribute value rather than in the name. If this is causing problems you could always just get rid of the attribute and use an element instead eg.<cd> <test1:test2>test</test1:test2></cd>

  8. I'm not quite sure where you got the example from because I can't see any code with a test1:test2 attribute? As far as I'm aware test1:test2 is an invalid attribute name, they may only contain letters, numbers, dots and hyphens.To answer your second question, you use a namespace declaration attribute in the root element of your document. Something like xmlns:SOAP="insert a URL for the namespace here". Then you prefix each element in that namespace with SOAP:See http://www.w3schools.com/xml/xml_namespaces.asp for more.

  9. Not really sure where I should post this but here will do!I am currently doing quite a bit of work on a data exchange format in XML. As part of this I need to use XLink and XPointer attributes quite frequently as one of the requirements is for the data in the documents to be 'linked' to its source. Currently, as far as I'm aware there is very little (if any) software/browser support for XPointer.My question is that would it be possible (and if so how difficult) for me to write a small application which could use the XPointer stuff. ie. you could load an XML document into it and through some sort of very simple interface it could say retrieve the source of the required data when asked to and display it in another frame for example?What are everyone's views on this? How difficult would it be to write, and if not too difficult what language would you recommend writing it in, I'm guessing either Java or VB?Thanks!!!

  10. So in other words, I guess the XSL you need is:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><xsl:value-of select="data/field/value[@date]" /><xsl:value-of select="data/field/value[@audience]" /><xsl:value-of select="data/field/value[@message]" /></xsl:template></xsl:stylesheet>

    Or just this<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><xsl:value-of select="data/field/value/@date" /><xsl:value-of select="data/field/value/@audience" /><xsl:value-of select="data/field/value/@message" /></xsl:template></xsl:stylesheet>
  11. To get a value of an attribute you use <xsl:value-of select="@attributename" />edit: or do you mean you want to use the attribute values in the xsl code so that all 3 of the value tags are displayed correctly and not just the first one 3 times? If so you can do this using XPath, specifically by identifying the position of the element you wish to extract the data from within its parent node. See http://www.w3schools.com/xpath/xpath_syntax.asp

  12. You are so right!Unfortunately it still doesn't work.The problem is the number of values within the tag.Normally i would write <Recipient>12345<Recipient/> and i would have no problem reading the data.How can i get hold of custno when the xml-file is created this way:<Recipient no="1" custno="12345"/>Regards imbr

    As said above, you need to make sure all your closing tags are the same as your opening tags, watch for capital letters!Again, closing tags are of the format </name> not <name/>. The reason i put it like <Recipient no="1" custno="12345" /> is that you are using an empty element and so you can use the shorthand of the /> at the end of the element. It is empty because you don't have any data stored in there, only attribute values. As mentioned above, it is generally a better idea to store data in element form as it is more versatile then.If the data has to be stored as attributes then you have to search for the data in the attributes. At the moment you are telling it to look for an element called custno, not an attribute.You need to change it to:<xsl:for-each select="Recipients/Recipient"><xsl:value-of select="@custno"/></xsl:for-each>the @ tells it to look for an attribute name and not an element name.
  13. HiHow can i read data from an xml file like this.<Recipients>    <Recipient no="1"custno="12345">    <Recipient no="2"custno="23456">    <Recipient no="3"custno="34567"></recipients>My problem is, that there are two values to select and it doesn't work.How can i get custno?????<xsl:for-each select="Recipients/Recipient"><xsl:value-of select="custno"/> :) RegardsImbr

    The problem is that you have used empty Recipient tags and no closed them properly. It should be: <Recipient no="1" custno="12345"/> <Recipient no="2" custno="23456"/> <Recipient no="3" custno="34567"/>
  14. I have developed two separate xslt stylesheets using XMLSpy, which I can quite happily apply individually to an xml document. The <xsl:output method="text"/> in both cases. One style sheet provides a list and the second a count based upon the value of child element.Ideally I would like to combine these into a single stylesheet. So I have created a stylesheet that combines the two, where I have separated all the variables at the beginning and then created two templates bounded in each case by <xsl:template> & </xsl:template>. It seems that the second template gets actioned but not the first. When I comment out the second then the first works fine. I have been playing with <xsl:apply-templates /> element to see if this can help me invoke multiple templates on the same xml document, but without success. Can anybody point me in the right direction?I am not sure I totally have grasped the nature of the <xsl:apply-templates /> element although I have been through w3schools tutorial, but that does not give examples of the mode attribute. Can anybody to some online resources to simply explain the use of this element?Appreciate your help.Good thoughts. Mike

    Could you maybe post the code you are using?
  15. I have written an XML file in Visual Studio.Net and then it has created a schema for me (hence there a few unecessary namespace references in there). The problem is that when i try to validate the xml file against the schema in Visual Studio it says it cannot locate the schema document, even though all the paths specified are correct. It could be a problem with Visual Studio because there are a few other features which are a bit iffy. I have tried looking for online tools that will check a document against a schema but only found http://apps.gotdotnet.com/xmltools/xsdvalidator/ which is offline at the moment!Is there any other way for me to check it, or can any of you see any errors i have made in the code? I'm not too bothered if there are a few small errors in the schema with regards to the syntax of the xml file at the moment but i just want to know why Visual Studio cannot locate the schema file to check againstMany thanksPractice.xml

    <?xml version="1.0" encoding="UTF-8"?><GeotechnicalProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns="http://www.dur.ac.uk/s.j.marjoribanks"  xsi:schemaLocation="practice.xsd">    <projectDetails>        <title>Practice XML file</title>        <date>2005-11-09</date>        <author>Stephen Marjoribanks</author>        <revision />        <notes>Sample borehole data taken from RF Craig Soil Mechanics 6th Edition, Table 10.1 pg419</notes>    </projectDetails>    <project>        <SiteInvestigation>            <holes>                <Borehole>                    <holeDetails>                        <Location>Barnhill</Location>                        <Method>Shell	&	Auger	to 14.4m,	Rotary core	drilling to	17.8m</Method>                        <Diameter>150</Diameter>                    </holeDetails>                    <groundProfile>                        <layer>                            <Top>0.00</Top>                            <Bottom>0.70</Bottom>                            <Name>Topsoil</Name>                            <Description>Topsoil</Description>                        </layer>                        <layer>                            <Top>0.70</Top>                            <Bottom>2.60</Bottom>                            <Name>Sand</Name>                            <Description>Loose,	lightly	brown	SAND</Description>                            <Constituent>                                <description>Sand</description>                                <type>Soil</type>                                <consistency>Loose</consistency>                                <mainColour>Light	brown</mainColour>                                <amount>Main</amount>                            </Constituent>                        </layer>                        <layer>                            <Top>2.60</Top>                            <Bottom>4.40</Bottom>                            <Name>Gravelly Sand</Name>                            <Description>Medium	dense, brown gravelly	SAND</Description>                            <Constituent>                                <description>Sand</description>                                <type>Soil</type>                                <consistency>Medium	dense</consistency>                                <mainColour>Brown</mainColour>                                <amount>Main</amount>                            </Constituent>                        </layer>                        <layer>                            <Top>4.40</Top>                            <Bottom>12.20</Bottom>                            <Name>Clay</Name>                            <Description>Firm	to stiff,	yellowish	brown, closely fissured	CLAY of	high plasticity</Description>                            <Constituent>                                <description>Clay</description>                                <type>Soil</type>                                <consistency>Firm	to Stiff</consistency>                                <plasticity>High</plasticity>                                <mainColour>Brown</mainColour>                                <secondaryColour>Yellow</secondaryColour>                                <amount>Main</amount>                                <notes>Closely fissured</notes>                            </Constituent>                        </layer>                        <layer>                            <Top>12.20</Top>                            <Bottom>14.40</Bottom>                            <Name>Sand</Name>                            <Description>Very	dense, red,	silty	SAND with	decomposed SANDSTONE</Description>                            <Constituent>                                <description>Sand</description>                                <type>Soil</type>                                <consistency>Very	dense</consistency>                                <mainColour>Red</mainColour>                                <amount>Main</amount>                                <notes>Silty</notes>                            </Constituent>                            <Constituent>                                <description>Sandstone</description>                                <type>Rock</type>                                <consistency>Decomposed</consistency>                                <mainColour />                                <amount>Secondary</amount>                            </Constituent>                        </layer>                        <layer>                            <Top>14.40</Top>                            <Bottom>17.80</Bottom>                            <Name>Sandstone</Name>                            <Description>Red,	medium-grained,	granular,	fresh	SANDSTONE, moderately	weak,	thickly	bedded</Description>                            <Constituent>                                <description>Sandstone</description>                                <type>Rock</type>                                <consistency>Granular</consistency>                                <mainColour>Red</mainColour>                                <grainSize>Medium</grainSize>                                <strength>Moderately weak</strength>                                <bedding>Thickly bedded</bedding>                                <notes>Fresh</notes>                            </Constituent>                        </layer>                    </groundProfile>                </Borehole>            </holes>        </SiteInvestigation>    </project></GeotechnicalProject>

    Practice.xsd

    <?xml version="1.0" encoding="UTF-8" ?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"	targetNamespace="http://www.dur.ac.uk/s.j.marjoribanks"	<!--xmlns="http://www.dur.ac.uk/s.j.marjoribanks"-->	<xs:element name="GeotechnicalProject">  <xs:complexType> 	 <xs:sequence>    <xs:element name="projectDetails">   	 <xs:complexType>      <xs:sequence>     	 <xs:element name="title" type="xs:string" minOccurs="1" />     	 <xs:element name="date" type="xs:date" minOccurs="0" />     	 <xs:element name="author" type="xs:string" minOccurs="0" />     	 <xs:element name="revision" type="xs:string" minOccurs="0" />     	 <xs:element name="notes" type="xs:string" minOccurs="0" />      </xs:sequence>   	 </xs:complexType>    </xs:element>    <xs:element name="project">   	 <xs:complexType>      <xs:sequence>     	 <xs:element name="SiteInvestigation" minOccurs="0" maxOccurs="unbounded">        <xs:complexType>       	 <xs:sequence>          <xs:element name="holes" minOccurs="0" maxOccurs="unbounded">         	 <xs:complexType>            <xs:sequence>           	 <xs:element name="Borehole" minOccurs="0" maxOccurs="unbounded">              <xs:complexType>             	 <xs:sequence>                <xs:element name="holeDetails" minOccurs="0" maxOccurs="unbounded">               	 <xs:complexType>                  <xs:sequence>                 	 <xs:element name="Location" type="xs:string" minOccurs="0" maxOccurs="1" />                 	 <xs:element name="Method" type="xs:string" minOccurs="0" maxOccurs="1" />                 	 <xs:element name="Diameter" type="xs:string" minOccurs="0" maxOccurs="1" />                  </xs:sequence>               	 </xs:complexType>                </xs:element>                <xs:element name="groundProfile" minOccurs="0" maxOccurs="1">               	 <xs:complexType>                  <xs:sequence>                 	 <xs:element name="layer" minOccurs="0" maxOccurs="unbounded">                    <xs:complexType>                   	 <xs:sequence>                      <xs:element name="Top" type="xs:float" fixed="1" />                      <xs:element name="Bottom" type="xs:float" fixed="1" />                      <xs:element name="Name" type="xs:string" minOccurs="0" />                      <xs:element name="Description" type="xs:string" minOccurs="0" />                      <xs:element name="Constituent" minOccurs="1" maxOccurs="unbounded">                     	 <xs:complexType>                        <xs:sequence>                       	 <xs:element name="description" type="xs:string" minOccurs="0" />                       	 <xs:element name="type" type="xs:string" fixed="1" />                       	 <xs:element name="consistency" type="xs:string" minOccurs="0" />                       	 <xs:element name="mainColour" type="xs:string" minOccurs="0" />                       	 <xs:element name="amount" type="xs:string" minOccurs="0" />                       	 <xs:element name="plasticity" type="xs:string" minOccurs="0" />                       	 <xs:element name="secondaryColour" type="xs:string" minOccurs="0" />                       	 <xs:element name="notes" type="xs:string" minOccurs="0" />                       	 <xs:element name="grainSize" type="xs:string" minOccurs="0" />                       	 <xs:element name="strength" type="xs:string" minOccurs="0" />                       	 <xs:element name="bedding" type="xs:string" minOccurs="0" />                        </xs:sequence>                     	 </xs:complexType>                      </xs:element>                   	 </xs:sequence>                    </xs:complexType>                 	 </xs:element>                  </xs:sequence>               	 </xs:complexType>                </xs:element>             	 </xs:sequence>              </xs:complexType>           	 </xs:element>            </xs:sequence>         	 </xs:complexType>          </xs:element>       	 </xs:sequence>        </xs:complexType>     	 </xs:element>      </xs:sequence>   	 </xs:complexType>    </xs:element> 	 </xs:sequence>  </xs:complexType>	</xs:element></xs:schema>

  16. Hi everyone, i'm hoping you can help me with a small code problem. I'm new to both HTML and XML and i've written just a very small .xml file to practice. I've also created an .xsl stylesheet which should display the data in a simple table in HTML. However when i open the file address.xml in internet explorer, the data has been sucessfully extracted from the XML file but it is just displayed as a long string of text not in the table as the stylesheet says. Basically, the HTML part isnt working for some reason. Hope you can help! Thanks :)Address.xml

     <?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="Address.xsl" ?><AddressBook xmlns="http://tempuri.org/Address.xsd"       schemaLocation="Address.xsd">    <Person>     <FirstName>Stephen</FirstName>        <Surname>Marjoribanks</Surname>        <University>Durham</University>        <College>Trevelyan</College>    </Person>    <Person>    <FirstName>Joe</FirstName>    <Surname>Bloggs</Surname>    <University>Leeds</University>    <College />  </Person></AddressBook>

    Address.xsl

    <?xml version="1.0" encoding="UTF-8" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">		<xsl:output method="html"/>  	<xsl:template match="/AddressBook">  <HTML> 	 <HEAD>    <TITLE>Address Book</TITLE> 	 </HEAD> 	 <BODY>    <H1>Address Book</H1><br/>    <HR/>    <TABLE BORDER="1">   	 <TD>First Name</TD>   	 <TD>Surname</TD>   	 <TD>University</TD>   	 <TD>College</TD>   	 <xsl:apply-templates/>    </TABLE> 	 </BODY>   </HTML>	</xsl:template>  		<xsl:template match="Person">  <TR> 	 <TD>    <xsl:value-of select="FirstName" /> 	 </TD> 	 <TD>    <xsl:value-of select="Surname" /> 	 </TD> 	 <TD>    <xsl:value-of select="University" /> 	 </TD> 	 <TD>    <xsl:value-of select="College" /> 	 </TD>  </TR>		</xsl:template>  </xsl:stylesheet>

×
×
  • Create New...