I have a third party component that produce serialized xml and stored procedure that parse xml and insert values into tables.
I am having trouble with xsi nil handled in the component and sql stored procedure. I don’t have control to change either the component or the stored procedure. So the IsNullable attribute on the property solution and not xsi=true on the procedure solution doesn’t help me.
I am trying to handle this using regex.
.*xsi\:nil\=\"true\" \/\>
The above regex match works perfect for the below input
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<prop1>
<prop11>abc</prop11>
<prop12 xsi:nil="true" />
<prop13>def</prop13>
</prop1>
</Root>
But not for this input
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><prop1><prop11>abc</prop11><prop12 xsi:nil="true" /><prop13>def</prop13></prop1></Root>
Desired output is
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<prop1>
<prop11>abc</prop11>
<prop13>def</prop13>
</prop1>
</Root>
Update:
The property name and the level is only known at run time. Please refer a different xml below
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<pa>
<paa>abc</paa>
<pab xsi:nil="true" />
<pac>def</pac>
<pad>
<pada>val1</pada>
<padb xsi:nil="true" />
<padc>
<padca>vala</padca>
<padcb xsi:nil="true" />
</padc>
<pad>
</prop1>
</Root>
The desired output for the above xml is
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<pa>
<paa>abc</paa>
<pac>def</pac>
<pad>
<pada>val1</pada>
<padc>
<padca>vala</padca>
</padc>
<pad>
</prop1>
</Root>
Could someone please help me
Thanks,
Esen
Using the XPath from this library: https://github.com/ChuckSavage/XmlLib/
I get the XElements that have
xsi:nil=truewith:I tested it with this XML:
And found all 4 XElements. From there they are removed.
The resulting XML is:
If you don’t care that the
xsi:nilis true, and you just want all nodes with thexsi:nilattribute removed, you can frame the XPath like: