Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-09

TDomNode to text and/or document

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Felipe Monteiro de Carvalho

Hello,

I have a TDomNode (laz2_dom, but I guess it should be the same for all implementations).

Is it possible to get a TXMLDocument from it? I tried:

  lDoc := TXMLDocument.Create;
  try
    lDoc.AppendChild(ANode);

but it crashes =(

Is it possible to get the full text of this node? something like:

<svg bla bla><sub item>etc etc etc</subitem></svg>

TextContent doesn't help at all here.

thanks,

Felipe Monteiro de Carvalho

Reply by email

Vojtěch Čihák
to Felipe Monteiro de Carvalho

Hi,
 
this is working code:
 
...
if not assigned(XMLDoc) then XMLDoc:=TXMLDocument.Create;   with XMLDoc do
    begin
      if not assigned(DocumentElement) then
        begin
          aNode:=CreateElement(cRoot);
          AppendChild(aNode); 
        end;  
      if ASchemeNode='' then ASchemeNode:=cScheme;       aNode:=DocumentElement.FindNode(ASchemeNode);        if not assigned(aNode) then
        begin
          aNode:=CreateElement(ASchemeNode);
          DocumentElement.AppendChild(aNode);         end;  
   ...
end;  
 
so simply you have to create DocumentElement (i.e. root node) and append children there.  
Vojtěch 
______________________________________________________________

Show quoted text 5 lines
Od: Felipe Monteiro de Carvalho Komu: "FPC-Pascal users discussions" Datum: 22.09.2014 12:38 Předmět: [fpc-pascal] TDomNode to text and/or document

Hello,

I have a TDomNode (laz2_dom, but I guess it should be the same for all implementations).

Is it possible to get a TXMLDocument from it? I tried:

  lDoc := TXMLDocument.Create;
  try
    lDoc.AppendChild(ANode);

but it crashes =(

Is it possible to get the full text of this node? something like:

<svg bla bla><sub item>etc etc etc</subitem></svg>

TextContent doesn't help at all here.

thanks,

Felipe Monteiro de Carvalho

Reply by email

Felipe Monteiro de Carvalho
to Vojtěch Čihák

Ummm, this doesn't seam to help much... but I eventually found googling.

The error is EDOMWrongDocument, which makes sense since I want to insert a TDOMNode from another document ... so I have to first import and then attach the node:

  lDoc := TXMLDocument.Create;
  try
    lImportedNode := lDoc.ImportNode(ANode, True);
    lDoc.AppendChild(lImportedNode);

By the way, whats the difference between TDOMNode and TDOMElement? Confusing...

Felipe Monteiro de Carvalho

Reply by email

Daniel Gaspary
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 10 lines
Ummm, this doesn't seam to help much... but I eventually found googling. The error is EDOMWrongDocument, which makes sense since I want to insert a TDOMNode from another document ... so I have to first import and then attach the node: lDoc := TXMLDocument.Create; try lImportedNode := lDoc.ImportNode(ANode, True); lDoc.AppendChild(lImportedNode);

I didn't knew this method, but looking the code I understand why. Is because it is almost an alias to CloneNode, the method I use.

By the way, whats the difference between TDOMNode and TDOMElement? Confusing...

TDomNode is the base class, can be an attribute, a Processing Instruction, a Text node...

TDomElement is one of its descendents.

Reply by email