|
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#?
|
|
|
|
|
I'm new to the XML world and have been previously using INI type files in old DOS aps and latley in C++ for .NET. Now we're on to the world of C#.
I know I can use XmlTextWriter, but the examples don't help too much. Let me set it up for you.
The application will have lots of settings that the user can play with. For example, there will be a serial number (text data) and there will be some float data (like a float for the span adjustment of the device). I want to be able to save the contents of a text box to a XML file and read it back. I also will read/write from the target board. So, how you propose I do it? I can see several catagories of items to save, then several items under each catagory.
The following C# code doesn't work because it doesn't like the "fi" in the second line:
FileInfo fi = new FileInfo(saveFileDialog1.FileName);
XmlTextWriter writer = new XmlTextWriter(fi);
That's how I would have done in C++ prior to writing to an INI file.
Any help will be great, but please be specific. I'm just getting started in XML!
Kenny O'Dell
Sr. R&D Software Engineer
Mettler-Toledo Inc.
Inman, SC
|
|
|
|
|
Hi,
There isn't an XmlTextWriter constructor that takes a FileInfo as a parameter. There's a choice of three constructors, it looks like you probably want to use this one:
public XmlTextWriter(string filename, Encoding encoding);
Cheers
Phil Hobgen
barbari.co.uk
Southampton, UK
|
|
|
|
|
I have a program that creates xml that can be loaded into excel and viewed as a spreadsheet. It is to be viewed as a web page and I set the mime type, no problem. But garbage is output - something is being lost in translation. Any ideas?
|
|
|
|
|
Could u possibly attach a snippet of ur code or just mail it to me so as to get a clear picture of what's actually happening. this would help me identify the glitch.
Regards
Wilbur
|
|
|
|
|
I am experimenting with "XmlValidatingReader" and want to create a event handler which gets called there occurs some validation error(schema mismatch etc..) But could not find where this class is located??
I am using .NET framework 2.0, VS 2005 beta1..
Is there any other way to validate xml with schema?
REgards.
MaulikCE
|
|
|
|
|
|
Phil,
Thanks for posting the link, meanwhile i have done with XmlValidatingREader.
But surprisingly Newer version i.e. XMLReaderSettings is not catching any XML errors, that are caught by XmlValidatingReader.
Can you throw some light!!!!
REgards.
MaulikCE
|
|
|
|
|
Hi,
Sorry, I haven't started working with it yet. I'd merely made myself a note that XmlValidatingReader will have to be replaced when I move some existing code to v2.0
Good Luck
Phil Hobgen
barbari.co.uk
Southampton, UK
|
|
|
|
|
hey,
I have wrote an application. In this I get a XML-Stream witch is stored in LPSTR-Variable. Is the StreamSize very great (more than 500k), I get an exception during:
loadXML(LPSTR XMLStream)
//************ code *******************//
LPSTR XMLStream; //get from external programm
if(!XMLStream)
return E_FAIL;
IXMLDOMDocumentPtr pDOMDoc(__uuidof(DOMDocument));
pDOMDoc->put_async(VARIANT_FALSE);
//load XML-Stream
//this will cause the exception
varResult = pDOMDoc->loadXML((_bstr_t)(XMLStream));
if(VARIANT_FALSE == varResult)
{
//do somthing
}
else if(VARIANT_TRUE == varResult)
{
//do somthing
}
//*****************************************************//
Is it possible, that there is some troubleshooting with the Header-Identifier
"encoding="ISO-8859-1" ??????
Thanks
|
|
|
|