Strat XML doc

Help
2001-06-18
2001-06-19
  • Jacek Markiewicz

    How crate sample XML doc

    <data attr="1">
      <name>Anna</name>
      <adrr>Wawelska</adrr>
    </data>

     
    • Oleg Sych

      Oleg Sych - 2001-06-19

      The simplest way to create this document is using generic attribute and element classes. The following example illustrates how to build an object representing your XML document.

      var
        DataElement: TJvxCompositeTextElement;
        AttrAttribute: TJvxIntegerAttribute;
        NameElement: TJvxStringElement;
        AdrrElement: TJvxStringElement;
        XMLGenerator: TJvxXMLGenerator;
      begin
        DataElement := TJvxCompositeTextElement.Create(nil);
        DataElement.NodeName := 'data';
       
        AttrAttribute := TJvxIntegerAttribute.Create(nil);
        AttrAttribute.NodeName := 'attr';
        AttrAttribute.Value := 1;
        AttrAttribute.Parent := DataElement;

        NameElement := TJvxStringElement.Create(nil);
        NameElement.NodeName := 'name';
        NameElement.Value := 'Anna';
        NameElement.Parent := DataElement;

        AdrrElement := TJvxStringElement.Create(nil);
        AdrrElement.NodeName := 'adrr';
        AdrrElement.Value := 'Wawelska';
        AdrrElement.Parent := DataElement;

        XMLGenerator := TJvxXMLGenerator.Create(nil);
        try
          ShowMessage(XMLGenerator.ContentFrom(Node));
        finally
          XMLGenerator.Free;
        end;

        DataElement.Free;
        // AttrAttribute - freed by DataElement
        // NameElement - freed by DataElement
        // AdrrElement - freed by DataElement
      end;

      You can also incapsulate <data> element in a class that will provide easy access properties for aggregated attr, <name> and <adrr>. Take a look at TJvxHTMLCustomElement, it is a good example of how you can create a class incapsulating XML element.

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks