0
을 나는 다음과 같은 XML이 :내가 부모 속성에 (xmlproperty) 이동하려면 어떻게 - Codesmith
<?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 %>
내가 루프 항목을 통해로서, 주소 '도시를 인쇄해야합니다. 기본적으로 부모 (또는 부모의 부모)를 트래버스하는 방법은 무엇입니까?
이것은 실제 문제를 모방하지 않는다는 것을 깨닫게 된 예입니다. 나는 절대 경로가 없으므로'var item = MyPurchaseOrder.Items [i];'이고'item'을 부모의'City' 속성을 얻는 다른 메소드에 전달합니다. 혼란을 드려 죄송합니다. – Nick