Click here to Skip to main content
15,171,576 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to remove the parent node of an xml in asp.net with c#. I want to remove the Request Node of the xml mentioned below code wise.
<pre><?xml version="1.0" encoding="utf-16"?>
<Request
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <webServiceRequest>
        <entityDetails>
            <entityId>123</entityId>
            <userName>TEST</userName>
            <password>TEST123</password>
            <serviceId>12344321</serviceId>
            <requesterWsiRef>WSI246744113661143180</requesterWsiRef>
        </entityDetails>
        <requestDetails>
            <encrypyedRequestKeyData>fye1gPxpyejR35ziHJyAAQ==</encrypyedRequestKeyData>
            <encryptedRequestData>o9mKUt4fdQHFoAMKMP+4UB8PCJItb5JZS9FszbvbM3Wg5fc8UWdGQxOCMNVieQjNgOtNebTY5xLnH41jOErJ/F5W2rY/KZrstrZZ76ifpjjtcCj/sgkcs3RoL5CnoBEpNaqWdr1c6/WXf2mKG9qSpcFy8nJACS0pDBCUFSFfXBICiLJZBM6puSl5LYcGcBq9N9tvtQrcHtK5OhxKSh4tw8/dYY7/iF4rJYR1feBLFSko0jrCBilGR4hq8JHLqDt0ei7hzdbUF5VoXYyy1W4eedias/vZlQbVFO7ut/M83NaghO/rxcd1c06KjQAHUa8L2Ue85zNUaaSMCGB2GOEpcoPtz2+8l92sR4lFVPTfLO1lTlrdaLPrN2ZGVg5P8z1U+2aRbxHgCJVNYwDTwEdHA8M5YlzWEpGeWC5RzkfhT3Df9OZLYdCImY+bSm+S4PIYr7yJGUXw2rA8581d6SeTvUvjhfBDxQ7srNK1lv0ucKzi7SmlzPF+Dj8HvugloZkgYwQZuoH4RyF9DpEDMnFGZMc9Ic4Fhjw26DDi13DIxK0pPIGv3Z6t/z6K82yIvI6rrLtLcEwhbbYr4tD6t8PaAvOXHIxYQXthTFEt3TsJQ/Cof5DSopzS0m7tyP9bStoF8WstwHuq7Rpdxe58oOc0AoB0QmZI/+Y1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ObQzjGd5h33AeeDQiuqE27Ud1p2+r3XPXwENMI5it2xEMYqjQJ1mGZ6NlKnePwxpwM0MF50gvksc8kQNwLAWOepvFGmEc/M9WCBa2dk1sM55QQ1mKO4HmMCA/e+KkofdQptgGbjK85WF57MgaEHWnSILs8wIZ1TzlfNsuffux7CE9rBjTxxDkYNgpENJxqSuU+FXyxfVaq/Gi3RPF5gYGfJ6jnwJgSHMQbMZMIuqQ4Q7TDPPU2i/Wn93+BiuUlx3k1dezQ4qhGOke+OPbXmkikBoOnyOK0vpx97+me9gJFXFgKp4ZplndYZb/fFV3urhJGvqpJPu4kaMWYKcdgTnsSxyGW2p3PZ3fNejpmwyx4ShPK35xYBxjiKh4iYeEmiONqHbOid5/GEYwVdMcoIhaM9/U1RYk4azapTtvbPFKsn3Zf+Kl6pRnkFLEtSxclsfpm41dzJ24oRQvOedEgLAetzcG74fEjY1F8qfysRUszTvvsA9EWlZtWz3hnHPrFVHb3ZWKTw8h7av/c/YnQJHOuJfB55H09rTt19eN4WbofhpkwO3yTAqjsSXrnZnG825gR/ToyHtoQGKgJ1nCajDDX7abhoRDwXR7h08v5nglo8CFkFYvHnwzS2+Oj1Hq6SuuQJds33mRlHCLBS0BIGHxXCX37Gu2hGG1RXHJcZLdVzG6kv9m+E0q5v4jbteMYUKnce3UFZ39yJQ0uk+utKWYh3eLLfPVuYkRYluyNRK6o+8F3V92ir7+fR9didcKVmBYHwlgwMMYoVSU9Jhqk+OddZpNZdSW2QgR9OOvJh04v+f4V0aa5eQ0k+TD2Pqh4aMVJtTTk99ZfYeypv0Ph/1ZSn+2nhQphVmxD7FL5OrFOeMSwLDQxewLvGIVIqkqM5nckDlRe1PBJWp8Zj3WDUf93Woo7rDqw9BBN/f8wTz2DUqDNE6eWVjftgcR36KnfwOcw==</encryptedRequestData>
        </requestDetails>
    </webServiceRequest>
</Request>


Node to remove of the above xml
<Request
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">




What I have tried:

Xml is as below:
<?xml version="1.0" encoding="utf-16"?>
<Request
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <webServiceRequest>
        <entityDetails>
            <entityId>123</entityId>
            <userName>TEST</userName>
            <password>TEST123</password>
            <serviceId>12344321</serviceId>
            <requesterWsiRef>WSI246744113661143180</requesterWsiRef>
        </entityDetails>
        <requestDetails>
            <encrypyedRequestKeyData>fye1gPxpyejR35ziHJyAAQ==</encrypyedRequestKeyData>
            <encryptedRequestData>o9mKUt4fdQHFoAMKMP+4UB8PCJItb5JZS9FszbvbM3Wg5fc8UWdGQxOCMNVieQjNgOtNebTY5xLnH41jOErJ/F5W2rY/KZrstrZZ76ifpjjtcCj/sgkcs3RoL5CnoBEpNaqWdr1c6/WXf2mKG9qSpcFy8nJACS0pDBCUFSFfXBICiLJZBM6puSl5LYcGcBq9N9tvtQrcHtK5OhxKSh4tw8/dYY7/iF4rJYR1feBLFSko0jrCBilGR4hq8JHLqDt0ei7hzdbUF5VoXYyy1W4eedias/vZlQbVFO7ut/M83NaghO/rxcd1c06KjQAHUa8L2Ue85zNUaaSMCGB2GOEpcoPtz2+8l92sR4lFVPTfLO1lTlrdaLPrN2ZGVg5P8z1U+2aRbxHgCJVNYwDTwEdHA8M5YlzWEpGeWC5RzkfhT3Df9OZLYdCImY+bSm+S4PIYr7yJGUXw2rA8581d6SeTvUvjhfBDxQ7srNK1lv0ucKzi7SmlzPF+Dj8HvugloZkgYwQZuoH4RyF9DpEDMnFGZMc9Ic4Fhjw26DDi13DIxK0pPIGv3Z6t/z6K82yIvI6rrLtLcEwhbbYr4tD6t8PaAvOXHIxYQXthTFEt3TsJQ/Cof5DSopzS0m7tyP9bStoF8WstwHuq7Rpdxe58oOc0AoB0QmZI/+Y1Pe4qAs6iD8IstJw/7oBnB2xvfp2x/zpiMrhTYUxluz6JgvWrEoo80eRosFPLXNvq1VS+cZo5fS2aG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QNwLAWOepvFGmEc/M9WCBa2dk1sM55QQ1mKO4HmMCA/e+KkofdQptgGbjK85WF57MgaEHWnSILs8wIZ1TzlfNsuffux7CE9rBjTxxDkYNgpENJxqSuU+FXyxfVaq/Gi3RPF5gYGfJ6jnwJgSHMQbMZMIuqQ4Q7TDPPU2i/Wn93+BiuUlx3k1dezQ4qhGOke+OPbXmkikBoOnyOK0vpx97+me9gJFXFgKp4ZplndYZb/fFV3urhJGvqpJPu4kaMWYKcdgTnsSxyGW2p3PZ3fNejpmwyx4ShPK35xYBxjiKh4iYeEmiONqHbOid5/GEYwVdMcoIhaM9/U1RYk4azapTtvbPFKsn3Zf+Kl6pRnkFLEtSxclsfpm41dzJ24oRQvOedEgLAetzcG74fEjY1F8qfysRUszTvvsA9EWlZtWz3hnHPrFVHb3ZWKTw8h7av/c/YnQJHOuJfB55H09rTt19eN4WbofhpkwO3yTAqjsSXrnZnG825gR/ToyHtoQGKgJ1nCajDDX7abhoRDwXR7h08v5nglo8CFkFYvHnwzS2+Oj1Hq6SuuQJds33mRlHCLBS0BIGHxXCX37Gu2hGG1RXHJcZLdVzG6kv9m+E0q5v4jbteMYUKnce3UFZ39yJQ0uk+utKWYh3eLLfPVuYkRYluyNRK6o+8F3V92ir7+fR9didcKVmBYHwlgwMMYoVSU9Jhqk+OddZpNZdSW2QgR9OOvJh04v+f4V0aa5eQ0k+TD2Pqh4aMVJtTTk99ZfYeypv0Ph/1ZSn+2nhQphVmxD7FL5OrFOeMSwLDQxewLvGIVIqkqM5nckDlRe1PBJWp8Zj3WDUf93Woo7rDqw9BBN/f8wTz2DUqDNE6eWVjftgcR36KnfwOcw==</encryptedRequestData>
        </requestDetails>
    </webServiceRequest>
</Request>
Posted
Updated 9-Jul-18 4:00am
Comments
[no name] 9-Jul-18 6:03am
   
You can just read XmlElement webServiceRequest from this XML object and do what ever you want with it....

1 solution

you can user XMLserializer class to implement it



Use something like

XmlSerializer s = new XmlSerializer(objectToSerialize.GetType());
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("","");
s.Serialize(xmlWriter, objectToSerialize, ns);



XmlSerializer Class (System.Xml.Serialization)[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900