[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

transformNodeToObject

Posted on 2009-04-24
5
Medium Priority
?
1,183 Views
Last Modified: 2012-05-06
My XSL generates plain string.
Input:
<?xml-stylesheet type="text/xsl" href="BasicInfo.xsl"?>
<Fields>
      <DOB>eeeee</DOB>
      <Name>qqqq</Name>
      <PlaceOfBirth>rrrrr</PlaceOfBirth>
      <Surname>wwwww</Surname>
</Fields>
XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
            <xsl:apply-templates select="//Fields"/>
      </xsl:template>      

      <xsl:template match="//Fields">
            <xsl:value-of select="Name"/><xsl:text> </xsl:text><xsl:value-of select="Surname"/> was born in <xsl:value-of select="PlaceOfBirth"/> on <xsl:value-of select="DOB"/>
            <xsl:text>&#10;</xsl:text>
      </xsl:template>

</xsl:stylesheet>

In browser transformation works and produces:
qqqq wwwww was born in rrrrr on eeeee
And this is correct.
I C++ I get empty string:

bool
CQsMSGScriptProcessor::transform (MSXML2::IXMLDOMDocumentPtr doc, MSXML2::IXMLDOMDocumentPtr transformation, string& result)
{
      if (doc == NULL || transformation == NULL) {
            return false;
      }

      try {
            IXMLDOMDocument2Ptr spDocResult;
            HRESULT hResult = spDocResult.CreateInstance(__uuidof(DOMDocument40));
            if (hResult != S_OK) {
                  return false;
            }

            VARIANT obj;
            obj.vt = VT_UNKNOWN;
            obj.pdispVal = spDocResult;
            BSTR bstr = NULL;

            HRESULT hr = doc->transformNodeToObject (transformation, obj);
            if (hr != S_OK) {
                  return false;
            }
            result = spDocResult->text;
            string s1 = spDocResult->Gettext();
            string s2 = spDocResult->Getxml();
            string s3 = "";
            //spDocResult->Release();
      }
      catch(_com_error &e) {
        _bstr_t d = e.ErrorMessage();
        _bstr_t f = e.Description();
        string msg = (char*) d;
            //string desc = (char*) f;
            return NULL;
      }
      return true;
}

In this code I am sending output to another DOM object.
all my
            result = spDocResult->text;
            string s1 = spDocResult->Gettext();
            string s2 = spDocResult->Getxml();
are empty strings.
How do I get the result?
Is it possible to output string instead of DOM object?

Best wishes,
Milan
0
Comment
Question by:milan_novkovic
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
milan_novkovic earned 0 total points
ID: 24226205
I wasn't aware that transformNode returns string and does not destroy input doc. So:

bool
CQsMSGScriptProcessor::transform (MSXML2::IXMLDOMDocumentPtr doc, MSXML2::IXMLDOMDocumentPtr transformation, string& result)
{
      if (doc == NULL || transformation == NULL) {
            return false;
      }
      try {
            result = doc->transformNode  (transformation);
            return true;
      }
      catch(_com_error &e) {
        _bstr_t d = e.ErrorMessage();
        _bstr_t f = e.Description();
        string msg = (char*) d;
            //string desc = (char*) f;
            return NULL;
      }
      return true;
}

Almost does the work for me
however, in:

result = doc->transformNode  (transformation);

my result string is prefixed with "<?xml version="1.0".....

I can trim it, off course, but what is the tidy way?

Best wishes,
Milan
0
 

Author Comment

by:milan_novkovic
ID: 24226350
xsl:output in transformation does the trick:

<xsl:output method="text" version="1.0" encoding="iso-8859-1" indent="no"/>

method="text"   gives me the clean output.

I'll leave the question open in case someone wants to comment on non-xml output from transformNodeToObject

0
 
LVL 39

Expert Comment

by:abel
ID: 24241874
do you mean that your question is resolved, or do you seek some more assistance with it?

> I can trim it, off course, but what is the tidy way?

the tidy way is to keep it. It is considered good practice (even Best Practice) to always have an XML declaration in the prologue of the XML. But that's if you want XML as output... otherwise:
> method="text"   gives me the clean output.

that will remove anything that has to do with XML. Apparently you were after getting text. The default, if you do not specify it, is XML. The indent="no|yes" will be ignored if the output is text, as will the version attribute (the indent is used for html and xml, the version is only used with xml).
0
 

Author Comment

by:milan_novkovic
ID: 24242267
Thanks Abel,

I did my work by using transform.
I was hoping to lern more about transformNodeToObject but as I ahvn't got any comments on that subject for a few days I'll close the question.
0
 
LVL 39

Expert Comment

by:abel
ID: 24242477
Ok, no problem.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question