|
hi,
i couldnt able to add a new element to a xml document using VC++ 6.0. im getting problem in appendChild function. if anyone having samples plz send it to kannaa_ram@yahoo.com
thanks and regards
kannan
|
|
|
|
|
I want to serialize (write) a DOM document out in an XML document.
1.How can i write <?xml version="1.0" encoding="UTF-8"?> and <!DOCTYPE rootElement SYSTEM "URIreference.dtd"> to the local file.
|
|
|
|
|
ladies & gentlemen.
i'm new in xerces xml dom. can anyone help me with following:
how can i get the XML content of the DOMDocument (as in msxml)?
there methods like, getTextContent... but it returns text without tags.
i've seen that java implemantation of xerces has DOMSerializer object.
maybe there is any analogical object...
any ideas?
4apai
There're no impossible tasks. There're tasks that required infinite period of execution time.
|
|
|
|
|
int main(int argc, char **argv)
{
int errorCount = 0;
try
{
XMLPlatformUtils::Initialize();
}
catch(const XMLException& toCatch)
{
cout << "XMLPlatformUtils::Initialize() failed." << endl;
XMLPlatformUtils::Terminate();
}
std::auto_ptr<xercesdomparser> pXercesDOMParser(new XercesDOMParser());
std::auto_ptr<mydomtreeerrorreporter> errReporter(new myDOMTreeErrorReporter());
pXercesDOMParser->setErrorHandler(errReporter.get());
XercesDOMParser::ValSchemes valScheme = XercesDOMParser::Val_Auto;
pXercesDOMParser->setValidationScheme(valScheme);
try
{
char filename[] = "config/command.xml";
pXercesDOMParser->parse(filename);
errorCount = pXercesDOMParser->getErrorCount();
if (errorCount > 0)
{
cout << "open file failed. 0" << endl;
XMLPlatformUtils::Terminate();
//goto Exit;
return 0;
}
}
catch (const DOMException& e)
{
cout << "open file failed. 1" << endl;
XMLPlatformUtils::Terminate();
return 0;
}
catch (const XMLException& e)
{
cout << "open file failed. 2" << endl;
XMLPlatformUtils::Terminate();
return 0;
}
DOMNode *pDOC = pXercesDOMParser->getDocument();
DOMNode *pNode = pDOC->getFirstChild();
//std::string name(getProp(pNode, "?xml"));
for (pNode = getNextElementNode(pNode);
pNode != NULL;
pNode = getNextElementNode(pNode))
{
/*if (!UtilXML::matchNode(pNode, "dictionary");
if (!matchNode(pNode, "dictionary"))
{
cout << "Bad dictionary format." << endl;
break;
}
std::string proto(getProp(pNode, "protocol"));
int currentProtocol = atol(proto.c_str());
#ifdef _DEBUG
cout << "protocol = " << currentProtocol << endl;
#endif
parseDictionary(pNode->getFirstChild(), currentProtocol);
*/
if(!matchNode(pNode, "command"))
{
cout << "Bad command format." << endl;
break;
}
parseCommand(pNode, 0);
}
//Exit:
pXercesDOMParser.release();
errReporter.release();
XMLPlatformUtils::Terminate();
return 0;
}
|
|
|
|
|
thx a lot. thats not really what i meant. but i find it helpful too.
4apai
There're no impossible tasks. There're tasks that required infinite period of execution time.
|
|
|
|
|
I have an XML File:
<ROOT>
<CAR Name="Maruti">
<SALES Year="2000">10</SALES>
<SALES Year="2001">11</SALES>
<SALES Year="2002">9</SALES>
<SALES Year="2004">8</SALES>
</CAR>
<CAR Name="Fort">
<SALES Year="2000">8</SALES>
<SALES Year="2002">7</SALES>
<SALES Year="2003">6</SALES>
<SALES Year="2004">9</SALES>
</CAR>
<CAR Name="Mercedes">
<SALES Year="2000">2</SALES>
<SALES Year="2001">4</SALES>
<SALES Year="2003">6</SALES>
<SALES Year="2004">3</SALES>
</CAR>
</ROOT>
Now I want to print the sales of each car Year wise in a tabular format. Something like a pivot table. If the car does not have sales for a particular year, it should display blank space. The output should be in the format like:
Maruti Fort Mercedes
2000 10 8 2
2001 11 - 4
2002 9 7 -
2003 - 6 6
2004 8 9 3
I am not able to print the values particularly. Please help.
|
|
|
|
|
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
|
|
|
|