EDIT:
I think what youre after is something roughly like the following, though since this uses id's that means they need to be unique withing the docuement so you cant ahve an order.id and a customer.id that are the same - not sure if there is a way around that. you could also alternatively use xsd:IDREFS
to do it like you posted in your original example i think, but personally i like it better this way...
<xsd:complexType name="Customer">
<xsd:attribute name="customerId" type="xsd:ID" use="required"/>
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="Order">
<xsd:sequence>
<xsd:element name="text" type="xsd:string"/>
<xsd:attribute name="customerId" type="xsd:IDREF" use="required"/>
<xsd:attribute name="id" type="xsd:ID" use="required"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="customers>
<xsd:sequence>
<xsd:element name="customer" type="CustomerType" />
</xsd:sequence>
</xsd:element>
<xsd:element name="orders">
<xsd:sequence>
<xsd:element name="order" type="OrderType" />
</xsd:sequence>
</xsd:element>
If i were you i would do something like:
<root>
<customers>
<customer id="unique-customer-id" name="CustomerA" />
</customers>
<orders>
<order id="222" customerId="unique-customer-id" text="Some Bananas..." />
</orders>
</root>
You can craft a schema to ensure that a order.customerId corresponds to a customer.id i would think this would aslo make lookup and transformation much easier. Of course you could make it even easier if orders were just children of the customer, but im sure you must have other requirements that make this too verbose or ill advised.