I though so....
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?
"John Saunders" <john.saunders at trizetto.comwrote in message
news:OM**************@TK2MSFTNGP04.phx.gbl...
"Yossi" <jo**********@firstfi.comwrote in message
news:u2**************@TK2MSFTNGP04.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 maping 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?
I think you're on your own.
I've never heard of a requirement like this. Instead of working against
the XPath, could you work from a schema?
Note that XPath, in general, is ambiguous. I hope that the XPath you're
being provided is restricted in helpful ways, like, no "//" or other
wildcards, no "..", no functions, etc. XPath isn't really good for
describing the structure of an XML document.
John