|
Hi,
This doesn't seem like a very elegant solution. I'm sure there must be a better way, but I couldn't get there
Hope this helps.
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="unique-years" select="/ROOT/CAR/SALES[not(@Year=preceding::*/@Year)]/@Year" />
<xsl:variable name="unique-carnames" select="/ROOT/CAR[not(@Name=preceding::*/Name)]/@Name" />
<html>
<body>
<table>
<tr>
<td> </td>
<xsl:for-each select="$unique-carnames">
<xsl:sort select="." />
<td><xsl:value-of select="." /></td>
</xsl:for-each>
</tr>
<xsl:for-each select="$unique-years">
<xsl:sort select="." />
<tr>
<xsl:variable name="this-year" select="."/>
<td><xsl:value-of select="$this-year" /></td>
<xsl:for-each select="$unique-carnames">
<xsl:sort select="." />
<xsl:variable name="this-car" select="."/>
<td><xsl:value-of select="/ROOT/CAR[@Name=$this-car]/SALES[@Year=$this-year]" /></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Cheers
Phil Hobgen
barbari.co.uk
Southampton, UK
|
|
|
|
|
Thanks a lot Phil. It works.
|
|
|
|
|
I am a beginner of xml programming.
I am going to transmission an image file, a text file and a video file through TCP/IP. Therefore, I want to group them by a xml file.
I don't know how to get start on it.
Can someone show me some guidelines?
Please help
|
|
|
|
|
Hi,
The best place to start is with some questions :
1) What's your development environment?
2) Is there an existing XML Schema that you need to comply with? If you are exchanging the data with an external system, a schema is useful as a definition of the exchanged data format. Alternatively you may just be able to agree a simple xml structure.
3) Do you need to enclose the binary data in the xml, or could you use a url within the xml to indicate where the binary data can be retrieved from? If you need to enclose the binary data then you will need to encode it, as xml does not allow binary data. Note that this encoding will expand the size of the binary data, and hence the size of your xml.
4) When you transmit via TCP/IP do you mean HTTP, a web service, or some other standard protocol or just from port to port using some 'informal' protocol?
A good link to bookmark is http://www.zvon.org[^]
Good Luck!
Cheers
Phil Hobgen
barbari.co.uk
Southampton, UK
|
|
|
|
|
Thank you for your reply. It is very helpful for me.
I am programming with C#.net in XP.
Moreover, I am using "TCPListener" and "TCPClient" and the data are transmitted by "StreamWriter" and "StreamReader".
-Can XML Schema be used in non-website case?
-I am not using web service. Can SOAP be used for binary data encoding?
If not, what should I use?
Regards
|
|
|
|
|
Hi,
XML can be used anywhere where you can use text. You can pass it around in files, or over the web. SOAP is a protocol that uses XML for sending/receiving to call methods, this doesn't sound like what you want.
To do the binary encoding take a look at base64 encoding.
Cheers
Phil Hobgen
barbari.co.uk
Southampton, UK
|
|
|
|
|
Hi,
I solve it. I learn a lot. Thank You.
Cheers
RockRock
|
|
|
|
|
Can somebody give me a GOOD START on XMI - Just the Basics.
I tried to get some information on What XMI is and its intended use, but did not get any useful information.
All I know of it is that it is an XML-based, stream representation of a UML model which has the potential to allow models to be shared between different UML tools.
I find tools to convert XMI to UML and vice versa, but no good start on what XMI is, what is it used for? The future of XMI or in other words, will it have a widespread use as XML has today.
I am told it would take the place of UML soon - How true is this Statement?
|
|
|
|
|
Hi,
A starting point would be the OMG web site generally, and maybe this page http://www.omg.org/technology/xml/index.htm[^] in particular.
From what I know, it's just an XML language for describing UML models so they can be exchanged between different vendors modelling tools. It can't take the place of UML as it is just a standard language for describing UML models. As for its' future - personally I can't see much call for it in the real world, except maybe for large open source projects where a number of different UML editors might be used by different contributors. From my experience organisations tend to standardise on the use of a single modelling tool, so unless they want to exchange models externally they would have no call for XMI.
I have no real idea, but perhaps it is possible be that certain vendors would like to use XMI to store the models generated by their modelling tools, however xml would seem to be an extremely inefficient way to store this data. A bit like storing very large spreadsheets as XML, only worse!
It would be interesting to hear what started your interest in XMI?
Cheers
Phil Hobgen
barbari.co.uk
Southampton, UK
|
|
|
|
|
Thank you Phil for the start.
I interest in XMI started as read an introductory article on it. I tried to search for more information on it and wasn't able find much to my dismay.
All GREAT Men were ORDINARY people to start with.
What you CANnot VISUALIZE you CANnot ACHIEVE.
|
|
|
|
|
I tried to use DOM to do the XML validation with XSD and I used IXMLDOMSchemaCollection.
I followed the example you can find at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmproschemas.asp
but when I arrive at instruction
hr = pSchemaCache->add("",pSchemaDDoc.GetInterfacePtr());
add() always crashed on me. In fact, I tried with some of
my own XSDs, and it crashed right at add() too.
I'm listing part of my source code below, it must be something that I missed. Please help.
Thanks!
IXMLDOMDocument2Ptr pXMLDoc = NULL;
CoInitialize(NULL);
HRESULT hr;
try
{
//load the schema file
IXMLDOMDocumentPtr pSchemaDoc;
hr = pSchemaDoc.CreateInstance(__uuidof(DOMDocument30));
pSchemaDoc->async = VARIANT_FALSE;
hr = pSchemaDoc->load("C:\\Progetti\\books.xsd");
//check on the parser error
if(hr!=VARIANT_TRUE)
{
MessageBox(NULL, "Error", "", MB_OK);
return false;
}
//create schemachache
IXMLDOMSchemaCollectionPtr pSchemaCache;
hr = pSchemaCache.CreateInstance(__uuidof(XMLSchemaCache30));
//add schema to schema cache
hr = pSchemaCache->add("", pSchemaDoc.GetInterfacePtr());
// load the XML file
// ****** you need to use IXMLDOMDocument2 interface *********
IXMLDOMDocument2Ptr pXMLDoc;
hr = pXMLDoc.CreateInstance(__uuidof(DOMDocument30));
pXMLDoc->validateOnParse = VARIANT_FALSE;
pXMLDoc->async = VARIANT_FALSE;
//associate xml doc with schemacache
pXMLDoc->schemas = pSchemaCache.GetInterfacePtr();
// relative path works in debugger, modify it with absolute path
hr = pXMLDoc->load("C:\\Progetti\\XMLfile.xml");
//check on the parser error
if(hr!=VARIANT_TRUE)
{
MessageBox(NULL, "Error", "", MB_OK);
return false;
}
//call validate
IXMLDOMParseErrorPtr pError;
pError = pXMLDoc->validate();
if(pError->errorCode != S_OK)
{
MessageBox(NULL,"validate error", "",MB_OK);
_bstr_t parseError = _bstr_t("Error code: ")+ _bstr_t(pError->errorCode) +_bstr_t("\n") + _bstr_t("Reason: ")+ pError->Getreason();
MessageBox(NULL, (char*)parseError, "Parse Error",MB_OK);
return false;
}
else
MessageBox(NULL,"Validation succeeded", "Results",MB_OK);
}
catch(_com_error e)
{
MessageBox(NULL, e.ErrorMessage(), "",MB_OK);
MessageBox(NULL, e.Source(), "",MB_OK);
return false;
}
return true;
|
|
|
|
|
I have a XML File of the format
<br />
<CRICKET><br />
<TEAM Name="INDIA"><br />
<PLAYER>India Player 1</PLAYER><br />
<PLAYER>India Player 2</PLAYER><br />
<PLAYER>India Player 3</PLAYER><br />
<PLAYER>India Player 4</PLAYER><br />
<PLAYER>India Player 5</PLAYER><br />
<PLAYER>India Player 6</PLAYER><br />
<PLAYER>India Player 7</PLAYER><br />
<PLAYER>India Player 8</PLAYER><br />
<PLAYER>India Player 9</PLAYER><br />
<PLAYER>India Player 10</PLAYER><br />
</TEAM><br />
<TEAM Name="PAKISTAN"><br />
<PLAYER>Pakistan Player 1</PLAYER><br />
<PLAYER>Pakistan Player 2</PLAYER><br />
<PLAYER>Pakistan Player 3</PLAYER><br />
<PLAYER>Pakistan Player 4</PLAYER><br />
<PLAYER>Pakistan Player 5</PLAYER><br />
<PLAYER>Pakistan Player 6</PLAYER><br />
<PLAYER>Pakistan Player 7</PLAYER><br />
<PLAYER>Pakistan Player 8</PLAYER><br />
<PLAYER>Pakistan Player 9</PLAYER><br />
<PLAYER>Pakistan Player 10</PLAYER><br />
</TEAM><br />
</CRICKET><br />
I want to print this file in a tabular format with the name of the country in te header and the name of the players as rows. That is in a tabular format. Below the name of the country there should be the name of the players. Can anyone help me.
|
|
|
|
|
Hi,
This should get you started - it's not in a table, but you should get there from here
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<h1>Cricket</h1>
<xsl:apply-templates select="CRICKET/TEAM"/>
</body>
</html>
</xsl:template>
<xsl:template match="TEAM">
<h2><xsl:value-of select="@Name" /></h2>
<xsl:apply-templates select="PLAYER"/>
</xsl:template>
<xsl:template match="PLAYER">
<h3><xsl:value-of select="." /></h3>
</xsl:template>
</xsl:stylesheet>
Cheers
Phil Hobgen
barbari.co.uk
Southampton, UK
|
|
|
|
|
Can anyone help me with this problem??
|
|
|
|
|
Hi,
I think what you want is the IXMLDOMDocumentType interface which inherits from an IXMLDOMNode so you should be able to deal with it like any other node.
Cheers
Phil Hobgen
barbari.co.uk
Southampton, UK
|
|
|
|
|
This is the case of the disappearing processing instruction.
I am writing a web-service. I am adding an XML processing instruction as shown in the code snipet below. (Sorry about the line wraps)
xmlDoc.LoadXml("<wsinfo>");
xmlDoc.InsertBefore(xmlDoc.CreateProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"wsinfo.xsl\""), xmlDoc.DocumentElement);
I can view the item in the debugger and see the PI in the InnerXML. I can still see the PI in the XmlDocument right before the webservice ends. Yet when the XML is displayed in IE, no PI... what gives?
IF I write the PI after the root, it remains in the returned XML however, IE seems to ignore it. The XSL is never executed and the result that I see in IE is the XML tree.
Can someone please point out the error of my ways? I am sure it is a stupid error at this point... I just can't see it.
Thanks!
John M. Saxton, Jr.
Microsoft Certified Application Developer for .NET
CompTIA Security+ Certified
|
|
|
|
|
Hi,
I've never seen the PI anywhere but before the root element. So that should be correct.
Are you sure that "wsinfo.xsl" is located relative to the url that returns the xml?
When you say the PI is not displayed in IE, do you mean in the browser or in the "View Source" notepad? The xml shouldn't be seen in the browser, you should see the result of the transformed xml.
Cheers
Phil Hobgen
barbari.co.uk
Southampton, UK
|
|
|
|
|
Phil,
Thanks for your reply.
As far as I know PIs may be anywhere in the XML, but I do want this one at the top as shown below:
<wsinfo>
I have verified that wsinfo.xsl is located in code and bin directories for the url that returns the XML. I know I don't need both, but for now I am trying everything.
When I say that the PI is not displayed, I mean that it is not present in the XML. Here is a snipet of the returned XML.
- <wsinfo>
I guess the exact point of the problem is that the PI is missing from the final XML. As a result the XML is not being transformed when it is dsiplayed in the browser. If I save the XML and open it in notepad ... there is no stylesheet PI.
Any clues?
P.S. The xsl is valid XML and if I manually add the stylesheet PI to the XML, it is properly transformed when displayed in IE.
John M. Saxton, Jr.
Microsoft Certified Application Developer for .NET
CompTIA Security+ Certified
|
|
|
|
|
Phil,
Thanks for your reply. The code didn't show up in the first post.
As far as I know PIs may be anywhere in the XML, but I do want this one at the top as shown below:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='wsinfo.xsl'?>
<WSInfo>
...
</WSInfo>
I have verified that wsinfo.xsl is located in code and bin directories for the url that returns the XML. I know I don't need both, but for now I am trying everything.
When I say that the PI is not displayed, I mean that it is not present in the XML. Here is a snipet of the returned XML.
<?xml version="1.0" encoding="utf-8"?>
<WSInfo>
...
</WSInfo>
I guess the exact point of the problem is that the PI is missing from the final XML. As a result the XML is not being transformed when it is dsiplayed in the browser. If I save the XML and open it in notepad ... there is no stylesheet PI.
Any clues?
P.S. The xsl is valid XML and if I manually add the stylesheet PI to the XML, it is properly transformed when displayed in IE.
John M. Saxton, Jr.
Microsoft Certified Application Developer for .NET
CompTIA Security+ Certified
|
|
|
|
|
Hi,
I'm not sure how you are transferring the xml to the browser. To work out if the problem is with the XmlDocument or with the transfer of the xml you could try a call to Save("SomeDirOnTheServer\\SomeFileName.xml");
Phil Hobgen
barbari.co.uk
Southampton, UK
|
|
|
|
|
Phil,
Added the Save. XML that gets saved has both PIs, which is as expected. Now I just need to get the ASP.NET app that is calling this webservice to display it properly. Its not optimal. I would rather have this webservice return a XmlDocument, but I can live with it returning a filename for now.
Thanks again.
John M. Saxton, Jr.
Microsoft Certified Application Developer for .NET
CompTIA Security+ Certified
|
|
|
|
|
I have an ASP.NET application which runs on server and clients only run IE to execute the application .
But i need each user to have a local XML file on his or her computer local hard disk and manipulate it by means of that server side application . In fact i need the user to have a XML file and IE on the client computer and nothing more. Can anybody tell me if it is possible or how can i do this .
Thanks
|
|
|
|
|
Well yep it is quite possible using client side scripting technologies like javascript and vbscript coupled with the filesystemobject or if u have a fixed path then the XMLDOM object has got a method called load() which will load the xml file from the client side and then u can play around with it. U can find many sample codes which will help u out with that and it's also very easy.
Regards Wilbur
|
|
|
|
|
I have an ASP.NET application which runs on server and clients only run IE to execute the application .
But i need each user to have a local XML file on his or her computer local hard disk and manipulate it by means of that server side application . In fact i need the user to have a XML file and IE on the client computer and nothing more. Can anybody tell me if it is possible or how can i do this .
Thanks
|
|
|
|
|
is there any way to generate xml file from existing schema in C#?
|
|
|
|