【问题标题】:Read XML file and display on web page读取 XML 文件并显示在网页上
【发布时间】:2017-06-13 18:22:54
【问题描述】:

请查看下面我试图在网页上显示的 XML 文件

<?xml version="1.0" encoding="utf-8" ?>
 <Quotation>
 <QuotationLines>
    <Line>
       <ItemID>Item ID 1</ItemID>
       <Description>
           <TextLine ID="1">Text Line 1 Item ID 1</TextLine>
           <TextLine ID="2">Text Line 2 Item ID 1</TextLine>
           <TextLine ID="3">Text Line 3 Item ID 1</TextLine>
       </Description>
    </Line>
    <Line>
        <ItemID>Item ID 2</ItemID>
        <Description>
            <TextLine ID="1">Text Line 1 Item ID 2</TextLine>
            <TextLine ID="2">Text Line 2 Item ID 2</TextLine>
        </Description>
    </Line>
  </QuotationLines>
 </Quotation>   

我希望它显示如下,因为我需要识别每个条目以最终保存到数据库中:

物品 ID 1
文本行 1 项目 ID 1
文本行 2 项目 ID 1
文本第 3 行项目 ID 1
项目 ID 2
文本行 1 项目 ID 2
文本行 1 项目 ID 2

我已经弄清楚如何显示 itemid,但不能只显示与该 item id 相关的文本行。

我的代码目前如下:

<%@ Page Language="vb" %>
<%@ Import Namespace="System.Xml" %>

<script runat="server" Language="VB">  

Sub page_load()  

Dim objxml As New XmlDocument()
objxml.load (Server.MapPath("test1.xml"))
Dim nodeList As XmlNodeList = objxml.SelectNodes("/Quotation/QuotationLines/Line")
For Each node As XmlNode In nodeList
response.Write(node("ItemID").InnerText &"<br>")
Next

end sub

    </script>

到目前为止,我已经花了 2 天时间试图让它工作,所以任何帮助都会得到很大的帮助。我对 asp.net 不是很了解,因为我仍然使用经典的 asp。

非常感谢 凯文

【问题讨论】:

    标签: c# asp.net xml vb.net


    【解决方案1】:

    你只需要第二个循环:

    For Each node As XmlNode In nodeList
        Response.Write(node("ItemID").InnerText & "<br>")
        For Each nodeDesc As XmlNode In node("Description").ChildNodes
            Response.Write(nodeDesc.InnerText & "<br />")
        Next
    Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-10
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多