I was hoping to find a function such as CreateAttribute(string XPath, string
data). For example:
CreateAttribute("/LOAN/_APPLICATION/ASSET/@_Type","Automobile") would create
the attribute and all needed parents if they don't exist:
<LOAN>
<_APPLICATION>
<ASSET _Type="Automobile">
</ASSET>
</_APPLICATION>
</LOAN>
If later on in the code I have this statement:
CreateAttribute("/LOAN/_APPLICATION/DOWN_PAYMENT/@_Type","CashOnHand"), it
will modify the above XML doc to:
<LOAN>
<_APPLICATION>
<ASSET _Type="Automobile">
</ASSET>
<DOWN_PAYMENT _Type="CashOnHand">
</DOWN_PAYMENT>
</_APPLICATION>
</LOAN>
In this following case, the function has to be smart enough to realize that
<ASSETalready has a _Type attribute, so it should create a new <ASSET>
element:
CreateAttribute("/LOAN/_APPLICATION/ASSET/@_Type","Automobile")
<LOAN>
<_APPLICATION>
<ASSET _Type="Automobile">
</ASSET>
<ASSET _Type="Automobile">
</ASSET>
<DOWN_PAYMENT _Type="CashOnHand">
</DOWN_PAYMENT>
</_APPLICATION>
</LOAN>
The tricky part now is to add nodes to an existing ASSET. I guess that
since both nodes look the same, we can add a node to either one:
CreateAttribute("/LOAN/_APPLICATION/ASSET/@_Type=\"Automobile\"/DESCRIPTION/@_Make","BMW")
<LOAN>
<_APPLICATION>
<ASSET _Type="Automobile">
<DESCRIPTION _Make="BMW">
</DESCRIPTION>
</ASSET>
<ASSET _Type="Automobile">
</ASSET>
<DOWN_PAYMENT _Type="CashOnHand">
</DOWN_PAYMENT>
</_APPLICATION>
</LOAN>
What abaout the year?
CreateAttribute("/LOAN/_APPLICATION/ASSET/@_Type=\"Automobile\"/DESCRIPTION/@_Make=\"BMW\"/@_Year","2006")
<LOAN>
<_APPLICATION>
<ASSET _Type="Automobile">
<DESCRIPTION _Make="BMW" _Year="2006">
</DESCRIPTION>
</ASSET>
<ASSET _Type="Automobile">
</ASSET>
<DOWN_PAYMENT _Type="CashOnHand">
</DOWN_PAYMENT>
</_APPLICATION>
</LOAN>
So I need to use String.Split() and walk the resulting array. I'll split at
'\'. I think I can use XPath to find an embeded node (i.e. ASSET inside
_APPLICATION inside LOAN). The thing is that I need to find the correct
ASSET node and the only thing that will differentiate them is what's on the
inside. Oh brother! This is going to be fun....
Any suggestions?
"Yossi" <jo**********@firstfi.comwrote in message
news:uw**************@TK2MSFTNGP05.phx.gbl...
Nice tool!
I am looking for something that will do the reverse. I have a whole bunch
of XPath statements and I need to use them to generate and populate an XML
document. I have mapping file that maps my data to a specific XPath. For
example:
Field# XPath
1 /LOAN/_APPLICATION/ASSET/@_Type
2 /LOAN/_APPLICATION/RESPA_FEE/_PAYMENT/@_IncludedInAPRIndicator
etc.
Do I have to parse every line myself or is there a .NET class that will do
this for me?