|
Hi Gurus!
I'm a XML beginner. I try to save my program settings in XML file using Microsoft Visual C++ 6.0. Here is the sample from my code:
--------------------------------------------------------------
IXMLDOMDocumentPtr XmlDocPtr;
IXMLDOMNodePtr pNode;
IXMLDOMElementPtr XmlRootPtr;
b=XmlDocPtr->loadXML(_bstr_t("<settings>"));
if (!b) return;
XmlDocPtr->get_documentElement(&XmlRootPtr);
if (XmlRootPtr)
{
VARIANT vtTemp2;
vtTemp2.vt=VT_I2;
vtTemp2.iVal = NODE_ELEMENT;
pNode = XmlDocPtr->createNode(vtTemp2, "Program", "");
pNode->put_dataType(L"NODE_TEXT");
pNode->put_text(L"MYCOOLER");
XmlRootPtr->appendChild(pNode);
pNode = XmlDocPtr->createNode(vtTemp2, "Distributor", "");
pNode->put_dataType(L"NODE_TEXT");
pNode->put_text(L"IBM Corp.");
XmlRootPtr->appendChild(pNode);
pNode = XmlDocPtr->createNode(vtTemp2, "Version", "");
pNode->put_dataType(L"NODE_TEXT");
pNode->put_text(L"6.0");
XmlRootPtr->appendChild(pNode);
};
variant_t vDest(L"d:\\settings.xml");
XmlDocPtr->save(vDest);
--------------------------------------------------------------
File d:\system.dtd contains:
--------------------------------------------------------------
--------------------------------------------------------------
But resulted file "settings.xml" is not formatted according system.dtd specification. What's wrong? Help me!
Yours sincerely,
Alex Bash
|
|
|
|
|
Bash wrote:
But resulted file "settings.xml" is not formatted according system.dtd specification.
The DTD is not a formatter. A DTD is just here to verify the well-formedness and/or validness of an Xml stream.
The formatting is the result of your own code (appendChild, ...).
On top of that, when you open an Xml file in MSIE, MSIE applies a default formatting (using a XSLT stylesheet) : for instance it may show you <k name="kkk"/> although there is <k name="kkk"></k> in the file.
Back to real work : D-27.
|
|
|
|
|
Hi,
Thank you for quick reply to the beginner. And another question - how to insert CR/LF symbol after appending a new child. At present, I have "settings.xml" with single line like as:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Settings><Program>MYCOOLER</Program><Distributor>IBM Corp.</Distributor><Version>6.0</Version></Settings>
I want to get this xml (i.e. "formatted") as follows:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Settings>
<Program>MYCOOLER</Program>
<Distributor>IBM Corp.</Distributor>
<Version>6.0</Version>
</Settings>
How to do "formatted" xml?
Yours sincerely,
Alex Bash
|
|
|
|
|
Unfortunately, there is no way to do so using MSXML. That's probably why this SDK is now legacy and replaced by a much more powerful Xml stuff along with .NET.
You can achieve indentation by creating your own fake text nodes, with code like this :
var dom = new ActiveXObject("Microsoft.XMLDOM");
var root = dom.createElement("toto");
for (i = 0; i < 10; i++) {
var formatting = dom.createTextNode("\n\t");
root.appendChild(formatting);
var child = dom.createElement(child);
root.appendChild(child);
}
dom.save("output.xml");
Back to real work : D-27.
|
|
|
|
|
Thank you, it works!
Yours sincerely,
Alex Bash
|
|
|
|
|
Do you know what would cause the construction of a Xerxes DOM parser to die? It seems like this should be valid, but I'm obviously missing something.
DOMParser* pDomParser = new DOMParser();
ASSERT (pDomParser != NULL);
delete pDomParser;
Are we required to derive from DOMParser and override certain methods? Btw, I'm using a prebuilt binary of the XML4C 4.0.0 implementation. A ptr to the API docs would also be much appreciated. Thanks!
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Are you calling the Initialize routine?
XMLPlatformUtils::Initialize();
What version are you using if not?
"We are what we repeatedly do. excellence, then, is not an act, but a habit." Aristotle
|
|
|
|
|
Thanks Michael, that did the trick!
I ended up with a purported memory leak, but the Xerxes docs say the diagnostic overagressive and can be ignored. I then switched from XML4C V4 to V5 and encountered a new problem:
When I build my (simple) Xerces test project, VC++ complains that DOMDocument (present in several Xerces header files) is an ambiguous symbol. The clash seems to occur as a result of the Platform SDK (Aug 2002) being installed on my system. Do you know how I get around this problem?
Thanks,
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I actually have not used the Xerces C since last Jan, so I am afraid no.
Have you downloaded the current release. There was an update the end of August so maybe it was addressed with that revision.
"We are what we repeatedly do. excellence, then, is not an act, but a habit." Aristotle
|
|
|
|
|
Yes, I'm using the latest release. I've switched back to version 4 to get around the symbol clash. Thanks for your help!
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi I am making a database that will be roughly 6 tiers. I have no problem constructing the first item that will go into the database but the second item gives me an exception error because i am unsure how to check too see if there already is an element in the database matching my new item.
Ex. I can construct this using the XmlDocument class
tier1/tier2/tier3/tier4/tier5/tier6/Bob/salary
When i try to add another person say Jane the first thing i do is attempt to reconstruct tier1 again. This gives me an exception because tier1 is already there. I require quite a few tiers to adequately group things, say tier2a, tier2b, ect.
How do i make it so if tier1 already exists then i don't try to recreate tier1, but instead set the tier1 element to an element in my program so that if i need to make a tier2c then i can have an element to make tier2c a child of?
|
|
|
|
|
This is a follow up on my "how do I do a join" question. I think I'm about to be screwed by .NET, because this is beginning to hurt so much.
Here's the problem. I created a database schema and data using .NET's DataSet:
dataSet.WriteXml(fn, XmlWriteMode.WriteSchema);
And it dutifully creates an XML document, with the data looking like this (as an example):
(BTW, how do you embed XML as source, so it doesn't get parsed, which is why all my example here have the opening '<' MISSING!!!):
PART>
ID>1001/ID>
PARTNUMBER>101045/PARTNUMBER>
DESC>FILTER, FUEL #2010SM RACOR/DESC>
/PART>
PART>
ID>1002/ID>
PARTNUMBER>101050/PARTNUMBER>
DESC>FILTER, #2020SM RACOR/DESC>
/PART>
Now, I've got an XSL translation that looks something like this:
?xml version="1.0" encoding="UTF-8" ?>
xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
xsl:template match="/">
xsl:for-each select="//PART[@*]">
xsl:value-of select="ID"/>
xsl:value-of select="PARTNUMBER"/>
/xsl:for-each>
/xsl:template>
/xsl:stylesheet>
as a test because it appears that fields like ID are not considered to be an attribute. (This select doesn't return any records, but a //PART[not(@*)] does return records. Instead, it seems that ID is an element (I hope I have my XPath terminology right here).
So, when I actually do an XPath query like:
xsl:for-each select="//PART[@ID='1001']">
I get no records back.
Argh! Can I do this on the XML file that DataSet created???
Thanks a million!
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator.
|
|
|
|
|
You're right - you're currently looking for this
<part id="1001">
Try
//part[id='1001']
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
|
You're welcome. As soon as you use the @, you're checking attributes, not nodes. Also, you can use text()= to check the value of the current node.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Marc Clifton wrote:
BTW, how do you embed XML as source, so it doesn't get parsed
Check the "Display this message as-is (no HTML)" checkbox before submitting the post.
--Mike--
"I'd rather you just give me a fish today, because even if you teach me how to fish, I won't do it. I'm lazy." -- Nish
Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Hi...
Does anyone no where I can get free Foreign Exchange rate data in XML? The ECB site looked good, but i'm having problems with their schema. Also, this data is Euro based and not US$ based. I would prefer US$ based. The US gov only has ascii flat files for download, and no XML
Any help would be appreciated!
thanks
-shane
|
|
|
|
|
|
How can i create a *.xml using msxml.dll in vc++ ? Any help links..
Thank you.
|
|
|
|
|
Create a new text file named *.xml, and save it;P
Please be more specific.
"The greatest danger to humanity is humanity without an open mind." - Ian Mariano
http://www.ian-space.com/
|
|
|
|
|
DOMDocument::save(...)
How low can you go ? (MS rant)
|
|
|
|
|
http://msdn.microsoft.com[^]
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
See this link[^] that explains how to do this, as well as other standard operations using MSXML.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi, I'm new to all this XML stuff, and I'm trying to figure out how I can code a table join like you can in SQL. Is this even possible with XML? I've got an XML file with 2 tables, and I'd like to perform a query where table1.id = table2.t1_id, for example. I've looked into XPath, and it doesn't seem like it can do the trick.
Thanks!
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator.
|
|
|
|
|
Depends on what you are looking for. Using a transformation xslt and using the XPath select in which you match the child element (or attribute) value, in the select statement, can give you the relation. I.E. select table 1 first and then for each child entity run a select of table 2 with the value from table 1 as part of the select statement. If you just want to use some of the values of the initial element (table 1) you can pass those values with the param usage and then only perform the output in the second template.
|
|
|
|