我有以下xml:
<?xml version="1.0"?>
<PurchaseOrder xmlns="http://www.codesmithtools.com/purchaseorder">
<ShipTo Name="Eric J. Smith">
<Line1>123 Test Dr.</Line1>
<City>Dallas</City>
<State>TX</State>
<Zip>75075</Zip>
</ShipTo>
<OrderDate>05-01-2003</OrderDate>
<Items>
<OrderedItem>
<ItemName>Item #1</ItemName>
<Description>Item #1 Description</Description>
<UnitPrice>5.45</UnitPrice>
<Quantity>3</Quantity>
<LineTotal>16.35</LineTotal>
</OrderedItem>
<OrderedItem>
<ItemName>Item #2</ItemName>
<Description>Item #2 Description</Description>
<UnitPrice>12.75</UnitPrice>
<Quantity>8</Quantity>
<LineTotal>102.00</LineTotal>
</OrderedItem>
</Items>
<SubTotal>45.23</SubTotal>
<ShipCost>5.23</ShipCost>
<TotalCost>50.46</TotalCost>
</PurchaseOrder>
我有以下 codesmith 模板:
<%@ XmlProperty Name="MyPurchaseOrder" Schema="PurchaseOrder.xsd" Default="SamplePurchaseOrder.xml" %>
PurchaseOrder:
Address:
Name: <%= MyPurchaseOrder.ShipTo.Name %>
Line1: <%= MyPurchaseOrder.ShipTo.Line1 %>
City: <%= MyPurchaseOrder.ShipTo.City %>
State: <%= MyPurchaseOrder.ShipTo.State %>
Zip: <%= MyPurchaseOrder.ShipTo.Zip %>
OrderDate: <%= MyPurchaseOrder.OrderDate %>
Items:
<% for (int i = 0; i < MyPurchaseOrder.Items.Count; i++) { %>
<%= i %>:
ItemName: <%= MyPurchaseOrder.Items[i].ItemName %>
//Here I need to traverse to the parent and print the City
Description: <%= MyPurchaseOrder.Items[i].Description %>
UnitPrice: <%= MyPurchaseOrder.Items[i].UnitPrice %>
Quantity: <%= MyPurchaseOrder.Items[i].Quantity %>
LineTotal: <%= MyPurchaseOrder.Items[i].LineTotal %>
<% } %>
SubTotal: <%= MyPurchaseOrder.SubTotal %>
ShipCost: <%= MyPurchaseOrder.ShipCost %>
TotalCost: <%= MyPurchaseOrder.TotalCost %>
当我遍历项目时,我需要打印地址的城市。本质上,我如何遍历到父级(或父级的父级)?