Board index » cppbuilder » Re: TXMLDocument

Re: TXMLDocument


2004-12-21 08:00:20 AM
cppbuilder99
"Veebo" < XXXX@XXXXX.COM >wrote in message
Quote
So what you're saying is that if I have Unicode enabled
controls that can have japanese characters as caption, then
I can write code to save that information in XML file. In that
case, XML will not complain about Japanese character?
All string values in TXMLDocument generally use WideString, which is
Unicode-enabled. As long as you are passing your strings to TXMLDocument,
and not manulating the XML file directly, then you should be ok.
Gambit
 
 

Re:Re: TXMLDocument

Quote
All string values in TXMLDocument generally use WideString, which is
Unicode-enabled. As long as you are passing your strings to TXMLDocument,
and not manulating the XML file directly, then you should be ok.


Gambit
Right. I just tried a sample project where XML file is
manipulated with using code, not directly, and everything
worked fine.
thanks for your help,
Veebo
 

Re:Re: TXMLDocument

Hello,
The component TXMLDocument does not work as expected.
If you have this XML
<A>
<B>Test</B>
</B>
and want the value of B you typically write
Bvalue =
XMLDoc->DocumentElement->ChildNodes->GetNode(String("B"))->GetText();
It works but if B has a label, the XML might look as this:
<A>
<B xmlns="My value">Test</B>
</B
this code does not work. Bvalue remains NULL
If you instead use this code
Bvalue = XMLDoc->DocumentElement->ChildNodes->GetNode(0)->GetText();
it works.
It seems that TXMLDocument cannot deal with these labels.
Is there an update, a patch, for TXMLDocument?
/Ivar
 

{smallsort}

Re:Re: TXMLDocument

"Ivar Suneson" < XXXX@XXXXX.COM >wrote in message
Quote
The component TXMLDocument does not work as expected.
Yes, it does. You are just using it wrong to begin with.
Quote
If you have this XML
<A>
<B>Test</B>
</B>
That is not valid XML by itself. You need the <? xml ?>prolog.
Quote
It works but if B has a label, the XML might look as this:
<A>
<B xmlns="My value">Test</B>
</B
this code does not work. Bvalue remains NULL
As it should be. GetText() only works on text nodes, which yours is not.
You need to use the NodeValue property instead of GetText(). You should
also be validating that the "B" actually exists before trying to access it.
Use this code instead:
_di_IXMLNode Doc = XMLDoc->DocumentElement;
if( Doc )
{
_di_IXMLNode Node = Doc->ChildNodes->FindNode("B");
if( Node )
{
// use Node->NodeValue as needed...
}
}
Quote
If you instead use this code
Bvalue = XMLDoc->DocumentElement->ChildNodes->GetNode(0)->GetText();
it works.
It seems that TXMLDocument cannot deal with these labels.
Yes, it can. You are just not taking into account that what you call
"labels" (which are actually called "attributes") are also treated as nodes
by the underlying XML parser.
Quote
Is there an update, a patch, for TXMLDocument?
There is none needed.
Gambit
 

Re:Re: TXMLDocument

Thanks for the lesson.
/Ivar
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >skrev i meddelandet
Quote

"Ivar Suneson" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>The component TXMLDocument does not work as expected.

Yes, it does. You are just using it wrong to begin with.

>If you have this XML
><A>
><B>Test</B>
></B>

That is not valid XML by itself. You need the <? xml ?>prolog.

>It works but if B has a label, the XML might look as this:
><A>
><B xmlns="My value">Test</B>
></B
>this code does not work. Bvalue remains NULL

As it should be. GetText() only works on text nodes, which yours is not.
You need to use the NodeValue property instead of GetText(). You should
also be validating that the "B" actually exists before trying to access
it.
Use this code instead:

_di_IXMLNode Doc = XMLDoc->DocumentElement;
if( Doc )
{
_di_IXMLNode Node = Doc->ChildNodes->FindNode("B");
if( Node )
{
// use Node->NodeValue as needed...
}
}

>If you instead use this code
>Bvalue = XMLDoc->DocumentElement->ChildNodes->GetNode(0)->GetText();
>it works.
>It seems that TXMLDocument cannot deal with these labels.

Yes, it can. You are just not taking into account that what you call
"labels" (which are actually called "attributes") are also treated as
nodes
by the underlying XML parser.

>Is there an update, a patch, for TXMLDocument?

There is none needed.


Gambit


 

Re:Re: TXMLDocument

Hi,
I need to create a XML document with a structure given by a XSD file.
So I use Delphi XML data Binding to create the Delphi classes to write this
file. This is very complex and long Schema. It is a AuditFile for Tax
Purposes.
To write the file, I'm using the TXMLDocument component (D7).
So, the problem is that when I have not so much data, everything is ok, the
file is created with no problems, but I have a
cliente with lots of data and when I start to load the data into my
TXMLDocument, the application will stop, raizing an "Out of memory" error.
The RAM will grow and grow until the error raizes (2GB of RAM).
So, I think this is a problem of TXMLDocument, isn't it?
How can I workaround this? Because of the complex file, I need to use Delphi
XML Data Binding.
Is this possible?
Thanks,
Carlos Matos
 

Re:Re: TXMLDocument

Hi Carlos,
Quote
How can I workaround this? Because of the complex file, I need to use
Delphi XML Data Binding.
You could also consider using the XML Mapper (available in Enterprise or
higher) and use a DataSet to enter the data, and then translate the
dataset to an XML file.
Quote
Is this possible?
If you have the Enterprise editior or higher...
See www.drbob42.com/examines/examin25.htm for a short article on
the XML Mapper.
Quote
Thanks,
Carlos Matos
Groetjes,
Bob Swart
--
Bob Swart Training & Consultancy (eBob42.com) Forever Loyal to Delphi
CodeGear Technology Partner -- CodeGear RAD Studio Reseller (BeNeLux)
Blog: www.drbob42.com/blog - RSS: eBob42.com/weblog.xml