Version 0.9  What is XML4Ada95?  Installation  How-To  API  Download 

COUNTER
counter


How to get informations from an XML-document

For example, the following XML-Document is given:
<person sex="male">
  <name>James</name>
</person>

You have parsed and validated this XML-document (so you can be sure it has the needed elements and attributes - if you don't know how to do that, read how to parse and how to validate a document). and hold a DOMDocument variable. Let's write two short functions that will return the sex of the person and her or his name.

function Return_Sex (Doc : DOMDocument) return Standard.String is
  Person : DOMElement;
begin
  Person := Document.Get_DocumentElement(Doc);
  return To_Standard_String(Element.GetAttribute(Person, From_Standard_String("sex"));
end Return_Sex;

function Return_Name (Doc : DOMDocument) return Standard.String is
  Person : DOMNode;
  Names_List : DOMNodeList;
  Name : DOMElement;
begin
  Person := Document.Get_DocumentElement(Doc);
  Names_List := Element.GetElementsByTagName(From_Standard_String("name"));
  Name := NodeList.item(0);
  Names_List := Node.Get_ChildNodes(Name);
  for i in 0..NodeList.Get_Length(Names_List)-1 loop
    if Node.Get_NodeType(NodeList.Item(i))=Node.Text_Node then
      Name := NodeList.Item(i);
    end if;
  end loop;
  return To_Standard_String(Node.Get_NodeValue(Name);
end Return_Name;


... parse a document ... validate a document ... get informations

e-Mail: denny@nodix.de

design shareright © 2002 Phlash  
inhalt © 2003-04 Zdenko Denny Vrandecic  
last update: 14.01.2004 website created by XML4Ada95 DocGen