一个由VB.Net生成的XML文件要怎么在Delphi里引用呢!
如果VB.Net生成的XML,在xmlmapper.exe转换后都可以在Delphi读取!
但如果不通过xmlmapper.exe来进行转换!
代码要怎么写着来着!

解决方案 »

  1.   

    能告诉我怎么写吗?
    XMLDocument这个我不会用!:(
      

  2.   

    看看dom解析器,下周一把例子发上来
      

  3.   

    在DELPHI中解析XML 其实也是采用的COM 组件,在DELPHI 的INTERNET组件栏中有一个XMLDOUCMENT组件,它代表一个XML文件,就是用来解析XML的,有LoadfromFile,savetofile等等,当然里面还有节点元素,IXMLNODE 用来遍历里面的节点的,详细使用可以参考XMLDOUCMENT的帮助文档,还有DELPHI 中有这样的例子的哦
      

  4.   

    直接使用TXMLDocument,简单又方便。我可以给你一些例子:比如下面是把Xml文件显示在了一个treeview里,
    procedure TFormXmlTree.btnLoadClick(Sender: TObject);
    begin
      OpenDialog1.InitialDir := ExtractFilePath (Application.ExeName);
      if OpenDialog1.Execute then
      begin
        XMLDocument1.LoadFromFile(OpenDialog1.FileName);
        Treeview1.Items.Clear;
        DomToTree (XMLDocument1.DocumentElement, nil);
        TreeView1.FullExpand;
      end;
    end;
       
    procedure TFormXmlTree.DomToTree (XmlNode: IXMLNode; TreeNode: TTreeNode);
    var
      I: Integer;
      NewTreeNode: TTreeNode;
      NodeText: string;
      AttrNode: IXMLNode;
    begin
      // skip text nodes and other special cases
      if XmlNode.NodeType <> ntElement then
        Exit;
      // add the node itself
      NodeText := XmlNode.NodeName;
      if XmlNode.IsTextElement then
        NodeText := NodeText + ' = ' + XmlNode.NodeValue;
      NewTreeNode := TreeView1.Items.AddChild(TreeNode, NodeText);
      // add attributes
      for I := 0 to xmlNode.AttributeNodes.Count - 1 do
      begin
        AttrNode := xmlNode.AttributeNodes.Nodes[I];
        TreeView1.Items.AddChild(NewTreeNode,
          '[' + AttrNode.NodeName + ' = "' + AttrNode.Text + '"]');
      end;
      // add each child node
      if XmlNode.HasChildNodes then
        for I := 0 to xmlNode.ChildNodes.Count - 1 do
          DomToTree (xmlNode.ChildNodes.Nodes [I], NewTreeNode);
    end;
    This code is interesting because it highlights some of the operations you can do with a DOM. First, each node has a NodeType property you can use to determine whether the node is an element, attribute, text node, or special entity (such as CDATA and others). Second, you cannot access the textual representation of the node (its NodeValue) unless it has a text element (notice that the text node will be skipped, as per the initial test). After displaying the name of the item, and then the text value if available, the program shows the content of each attribute directly and of each subnode by calling the DomToTree method recursively