BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Self inherited of Node attribute.

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi XML
View previous topic :: View next topic  
Author Message
mia gomez
Guest





PostPosted: Wed Feb 14, 2007 10:58 pm    Post subject: Self inherited of Node attribute. Reply with quote



Hi all,
I'm working with BDS 2006 Upg1, XPProf SP2, P4 1GBRAM.
I'm building a xml doc, like others I've do, but with this doc I have a problem.
In the DocumentElement Node, I put the xmlns attrib. ok no problem. but when I insert a new child to the DocumentElement the xmlns attrib is also created in the new node, but empty.
How i must do to not create this attrib in the childnodes?

My code:
----------------------------------------------------------
xmlDoc := TXMLDocument.Create(tblConfig.Owner);
try
xmlDoc.Version = '1.0';
xmlDoc.Active := TRUE;
xmlElement := xmlDoc.CreateNode(xmlTC_FunctionCallRequest);

xmlElement.SetAttribute('xmlns:xsd','myString');
xmlElement.SetAttribute('xmlns:xsi','myOtherString');
xmlElement.SetAttribute('xmlns','myAnotherString');

xmlDoc.DocumentElement := xmlElement;
xmlNode := xmlElement.AddChild(xmlTC_TimeStamp);
...
----------------------------------------------------

The result:
-----------------------------------------------------
<FunctionCallRequest xmlns:xsd="MyString" xmlns:xsi="MyOtherString" xmlns="MyAnotherString">
<Timestamp xmlns="">
.....

---------------------------------------------------
<Timestamp xmlns=""> is the problem. Must be <TimeStamp>

Sorry for my English and thanks in advance.
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Feb 15, 2007 12:52 am    Post subject: Re: Self inherited of Node attribute. Reply with quote



"mia gomez" <josepmariagomez (AT) terra (DOT) es> wrote in message
news:45d33fac$1 (AT) newsgroups (DOT) borland.com...

Quote:
In the DocumentElement Node, I put the xmlns attrib. ok no problem.
but when I insert a new child to the DocumentElement the xmlns
attrib
is also created in the new node, but empty.

That is because you are not actually assigning the namespace for the
DocumentElement, so it is not available when child nodes are created.
Do not use SetAttribute() to declare a namespace. You need to use the
DeclareNamespace() method instead, ie:

xmlElement.DeclareNamespace('xsd', 'myString');
xmlElement.DeclareNamespace('xsi', 'myOtherString');
xmlElement.DeclareNamespace('', 'myAnotherString');


Gambit
Back to top
Mia Gómez
Guest





PostPosted: Thu Feb 15, 2007 6:03 pm    Post subject: Re: Self inherited of Node attribute. Reply with quote



"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

"mia gomez" <josepmariagomez (AT) terra (DOT) es> wrote in message
news:45d33fac$1 (AT) newsgroups (DOT) borland.com...

In the DocumentElement Node, I put the xmlns attrib. ok no problem.
but when I insert a new child to the DocumentElement the xmlns
attrib
is also created in the new node, but empty.

That is because you are not actually assigning the namespace for the
DocumentElement, so it is not available when child nodes are created.
Do not use SetAttribute() to declare a namespace. You need to use the
DeclareNamespace() method instead, ie:

xmlElement.DeclareNamespace('xsd', 'myString');
xmlElement.DeclareNamespace('xsi', 'myOtherString');
xmlElement.DeclareNamespace('', 'myAnotherString');

Many thanks Remy,
but doesn't work.
Still appears the xmlns="". Is like the namespace is inherited to all child nodes I create in the DocumentElement.
Also I've tryied to put the namespace to the DocumentElement after I've added the child nodes, but the empty namespace appears too.
Also I've tried modifying xmlDoc.Options, but doesn' work too.

Any other idea?
Many thanks....

Mia.
Back to top
Mia Gómez
Guest





PostPosted: Thu Feb 15, 2007 10:14 pm    Post subject: Re: Self inherited of Node attribute. Reply with quote

"Mia Gómez" <josepmariagomez (AT) terra (DOT) es> wrote:
Quote:

"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:

"mia gomez" <josepmariagomez (AT) terra (DOT) es> wrote in message
news:45d33fac$1 (AT) newsgroups (DOT) borland.com...

In the DocumentElement Node, I put the xmlns attrib. ok no problem.
but when I insert a new child to the DocumentElement the xmlns
attrib
is also created in the new node, but empty.

That is because you are not actually assigning the namespace for the
DocumentElement, so it is not available when child nodes are created.
Do not use SetAttribute() to declare a namespace. You need to use the
DeclareNamespace() method instead, ie:

xmlElement.DeclareNamespace('xsd', 'myString');
xmlElement.DeclareNamespace('xsi', 'myOtherString');
xmlElement.DeclareNamespace('', 'myAnotherString');

Many thanks Remy,
but doesn't work.
Still appears the xmlns="". Is like the namespace is inherited to all child nodes I create in the DocumentElement.
Also I've tryied to put the namespace to the DocumentElement after I've added the child nodes, but the empty namespace appears too.
Also I've tried modifying xmlDoc.Options, but doesn' work too.

Any other idea?
Many thanks....

Mia.


Hi all again,
I've solved this problem !!
Once declared a namespace in the DocumentElement, all child nodes must be created in the same namespace.
If the child nodes don't have nameSpace xmlns will be "". If the child nodes have a nameSpace diferent than the father node then the xmlns will be the child nameSpace (this last example may be incongruent, because i can't see why a child may be another nameSpace than the father node.)

-BeginCode----------------------------------------
var
xmlDoc: TXMLDocument;
xmlElement,
xmlNode,
xmlNode1 : IXMLNode;
strNameSpace: string;
begin
xmlDoc := TXMLDocument.Create(Self.Owner);
try
strNameSpace := 'myNameSpace';
xmlDoc.Active := TRUE;
xmlDoc.Version := '1.0';
xmlElement := xmlDoc.CreateNode(xmlTC_FunctionCallRequest);
xmlElement.DeclareNamespace('xsd', 'myXSD');
xmlElement.DeclareNamespace('xsi', 'myXSI');
xmlElement.DeclareNamespace('', strNameSpace);
xmlDoc.DocumentElement := xmlElement;
/// In the child node creation, we must put the same
/// simple namespace than father node!!!
xmlNode := xmlElement.AddChild('FirstNode',strNameSpace);
xmlNode1 := xmlElement.AddChild('SecondNode',strNameSpace);
...
-EndCode----------------------------------------

Thanks a lot Remy. You put me on the way to solve it.

Mia
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi XML All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.