Get specific XML data using C#












-1















<hashtable>
<entry>
<string>recsonpage</string>
&gt;
<string>1</string>
</entry>
<entry>
<string>recsindb</string>
<string>1</string>
</entry>
<entry>
<string>1</string>
<hashtable>
<entry>
<string>orders.orderid</string>
<string>84344969</string>
</entry>
<entry>
<string>entity.customerid</string>
<string>19421067</string>
</entry>
<entry>
<string>entity.entityid</string>
<string>84344969</string>
</entry>
<entry>
<string>orders.autorenew</string>
<string>false</string>
</entry>
<entry>
<string>orders.endtime</string>
<string>1572414460</string>
</entry>
<entry>
<string>orders.resellerlock</string>
<string>false</string>
</entry>
<entry>
<string>orders.timestamp</string>
<string>2018-10-30 05:47:41.791511+00</string>
</entry>
<entry>
<string>orders.customerlock</string>
<string>true</string>
</entry>
<entry>
<string>entity.entitytypeid</string>
<string>87</string>
</entry>
<entry>
<string>entity.currentstatus</string>
<string>Active</string>
</entry>
<entry>
<string>entitytype.entitytypekey</string>
<string>dotco</string>
</entry>
<entry>
<string>orders.transferlock</string>
<string>true</string>
</entry>
<entry>
<string>orders.creationtime</string>
<string>1540878460</string>
</entry>
<entry>
<string>orders.privacyprotection</string>
<string>false</string>
</entry>
<entry>
<string>entitytype.entitytypename</string>
<string>.CO Domain Name</string>
</entry>
<entry>
<string>orders.creationdt</string>
<string>1540878459</string>
</entry>
<entry>
<string>entity.description</string>
<string>testlbapi.co</string>
</entry>
</hashtable>
</entry>
</hashtable>


Hi All. I need help on how to get the data of orders.orderid, entity.description of this XML Data. I used XElement but it gets the whole content of this XML Data. Any idea on this? Thank you in advance. Hi All. I need help on how to get the data of orders.orderid, entity.description of this XML Data. I used XElement but it gets the whole content of this XML Data. Any idea on this? Thank you in advance.










share|improve this question

























  • Hi @IrisLorrenHequibal, please, do not repeat your message just to get rid of SO warnings, instead try to provide more information, so that your chances of getting help will be higher!

    – toti08
    Nov 20 '18 at 7:01











  • You already asked the same thing about JSON. This XML schema is actually harder to query than a JSON file. What are you trying to do? Why not use proper elements and attributes instead of dumping a hashtable into unordered XML? A useful XML schema would be <entity><orders/><entityType/></entity>.

    – Panagiotis Kanavos
    Nov 20 '18 at 7:43













  • This sounds like an XY Problem. You have a problem with X and assume the solution is Y. When that doesn't work, you ask about Y, not X. In this case you assume that X will be solved by changing how you serialize unordered data. What is the actual problem you want to solve? Where does this data come from? A database? Another system? Why not create proper objects to model it and serialize it to XML or JSON?

    – Panagiotis Kanavos
    Nov 20 '18 at 7:47













  • it's coming from an API URL.

    – Iris Lorren Hequibal
    Nov 20 '18 at 8:28











  • Pretty printed the xml.

    – LosManos
    Nov 20 '18 at 9:35
















-1















<hashtable>
<entry>
<string>recsonpage</string>
&gt;
<string>1</string>
</entry>
<entry>
<string>recsindb</string>
<string>1</string>
</entry>
<entry>
<string>1</string>
<hashtable>
<entry>
<string>orders.orderid</string>
<string>84344969</string>
</entry>
<entry>
<string>entity.customerid</string>
<string>19421067</string>
</entry>
<entry>
<string>entity.entityid</string>
<string>84344969</string>
</entry>
<entry>
<string>orders.autorenew</string>
<string>false</string>
</entry>
<entry>
<string>orders.endtime</string>
<string>1572414460</string>
</entry>
<entry>
<string>orders.resellerlock</string>
<string>false</string>
</entry>
<entry>
<string>orders.timestamp</string>
<string>2018-10-30 05:47:41.791511+00</string>
</entry>
<entry>
<string>orders.customerlock</string>
<string>true</string>
</entry>
<entry>
<string>entity.entitytypeid</string>
<string>87</string>
</entry>
<entry>
<string>entity.currentstatus</string>
<string>Active</string>
</entry>
<entry>
<string>entitytype.entitytypekey</string>
<string>dotco</string>
</entry>
<entry>
<string>orders.transferlock</string>
<string>true</string>
</entry>
<entry>
<string>orders.creationtime</string>
<string>1540878460</string>
</entry>
<entry>
<string>orders.privacyprotection</string>
<string>false</string>
</entry>
<entry>
<string>entitytype.entitytypename</string>
<string>.CO Domain Name</string>
</entry>
<entry>
<string>orders.creationdt</string>
<string>1540878459</string>
</entry>
<entry>
<string>entity.description</string>
<string>testlbapi.co</string>
</entry>
</hashtable>
</entry>
</hashtable>


Hi All. I need help on how to get the data of orders.orderid, entity.description of this XML Data. I used XElement but it gets the whole content of this XML Data. Any idea on this? Thank you in advance. Hi All. I need help on how to get the data of orders.orderid, entity.description of this XML Data. I used XElement but it gets the whole content of this XML Data. Any idea on this? Thank you in advance.










share|improve this question

























  • Hi @IrisLorrenHequibal, please, do not repeat your message just to get rid of SO warnings, instead try to provide more information, so that your chances of getting help will be higher!

    – toti08
    Nov 20 '18 at 7:01











  • You already asked the same thing about JSON. This XML schema is actually harder to query than a JSON file. What are you trying to do? Why not use proper elements and attributes instead of dumping a hashtable into unordered XML? A useful XML schema would be <entity><orders/><entityType/></entity>.

    – Panagiotis Kanavos
    Nov 20 '18 at 7:43













  • This sounds like an XY Problem. You have a problem with X and assume the solution is Y. When that doesn't work, you ask about Y, not X. In this case you assume that X will be solved by changing how you serialize unordered data. What is the actual problem you want to solve? Where does this data come from? A database? Another system? Why not create proper objects to model it and serialize it to XML or JSON?

    – Panagiotis Kanavos
    Nov 20 '18 at 7:47













  • it's coming from an API URL.

    – Iris Lorren Hequibal
    Nov 20 '18 at 8:28











  • Pretty printed the xml.

    – LosManos
    Nov 20 '18 at 9:35














-1












-1








-1








<hashtable>
<entry>
<string>recsonpage</string>
&gt;
<string>1</string>
</entry>
<entry>
<string>recsindb</string>
<string>1</string>
</entry>
<entry>
<string>1</string>
<hashtable>
<entry>
<string>orders.orderid</string>
<string>84344969</string>
</entry>
<entry>
<string>entity.customerid</string>
<string>19421067</string>
</entry>
<entry>
<string>entity.entityid</string>
<string>84344969</string>
</entry>
<entry>
<string>orders.autorenew</string>
<string>false</string>
</entry>
<entry>
<string>orders.endtime</string>
<string>1572414460</string>
</entry>
<entry>
<string>orders.resellerlock</string>
<string>false</string>
</entry>
<entry>
<string>orders.timestamp</string>
<string>2018-10-30 05:47:41.791511+00</string>
</entry>
<entry>
<string>orders.customerlock</string>
<string>true</string>
</entry>
<entry>
<string>entity.entitytypeid</string>
<string>87</string>
</entry>
<entry>
<string>entity.currentstatus</string>
<string>Active</string>
</entry>
<entry>
<string>entitytype.entitytypekey</string>
<string>dotco</string>
</entry>
<entry>
<string>orders.transferlock</string>
<string>true</string>
</entry>
<entry>
<string>orders.creationtime</string>
<string>1540878460</string>
</entry>
<entry>
<string>orders.privacyprotection</string>
<string>false</string>
</entry>
<entry>
<string>entitytype.entitytypename</string>
<string>.CO Domain Name</string>
</entry>
<entry>
<string>orders.creationdt</string>
<string>1540878459</string>
</entry>
<entry>
<string>entity.description</string>
<string>testlbapi.co</string>
</entry>
</hashtable>
</entry>
</hashtable>


Hi All. I need help on how to get the data of orders.orderid, entity.description of this XML Data. I used XElement but it gets the whole content of this XML Data. Any idea on this? Thank you in advance. Hi All. I need help on how to get the data of orders.orderid, entity.description of this XML Data. I used XElement but it gets the whole content of this XML Data. Any idea on this? Thank you in advance.










share|improve this question
















<hashtable>
<entry>
<string>recsonpage</string>
&gt;
<string>1</string>
</entry>
<entry>
<string>recsindb</string>
<string>1</string>
</entry>
<entry>
<string>1</string>
<hashtable>
<entry>
<string>orders.orderid</string>
<string>84344969</string>
</entry>
<entry>
<string>entity.customerid</string>
<string>19421067</string>
</entry>
<entry>
<string>entity.entityid</string>
<string>84344969</string>
</entry>
<entry>
<string>orders.autorenew</string>
<string>false</string>
</entry>
<entry>
<string>orders.endtime</string>
<string>1572414460</string>
</entry>
<entry>
<string>orders.resellerlock</string>
<string>false</string>
</entry>
<entry>
<string>orders.timestamp</string>
<string>2018-10-30 05:47:41.791511+00</string>
</entry>
<entry>
<string>orders.customerlock</string>
<string>true</string>
</entry>
<entry>
<string>entity.entitytypeid</string>
<string>87</string>
</entry>
<entry>
<string>entity.currentstatus</string>
<string>Active</string>
</entry>
<entry>
<string>entitytype.entitytypekey</string>
<string>dotco</string>
</entry>
<entry>
<string>orders.transferlock</string>
<string>true</string>
</entry>
<entry>
<string>orders.creationtime</string>
<string>1540878460</string>
</entry>
<entry>
<string>orders.privacyprotection</string>
<string>false</string>
</entry>
<entry>
<string>entitytype.entitytypename</string>
<string>.CO Domain Name</string>
</entry>
<entry>
<string>orders.creationdt</string>
<string>1540878459</string>
</entry>
<entry>
<string>entity.description</string>
<string>testlbapi.co</string>
</entry>
</hashtable>
</entry>
</hashtable>


Hi All. I need help on how to get the data of orders.orderid, entity.description of this XML Data. I used XElement but it gets the whole content of this XML Data. Any idea on this? Thank you in advance. Hi All. I need help on how to get the data of orders.orderid, entity.description of this XML Data. I used XElement but it gets the whole content of this XML Data. Any idea on this? Thank you in advance.







c# xml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 10:21









er-sho

6,0672617




6,0672617










asked Nov 20 '18 at 6:34









Iris Lorren HequibalIris Lorren Hequibal

12




12













  • Hi @IrisLorrenHequibal, please, do not repeat your message just to get rid of SO warnings, instead try to provide more information, so that your chances of getting help will be higher!

    – toti08
    Nov 20 '18 at 7:01











  • You already asked the same thing about JSON. This XML schema is actually harder to query than a JSON file. What are you trying to do? Why not use proper elements and attributes instead of dumping a hashtable into unordered XML? A useful XML schema would be <entity><orders/><entityType/></entity>.

    – Panagiotis Kanavos
    Nov 20 '18 at 7:43













  • This sounds like an XY Problem. You have a problem with X and assume the solution is Y. When that doesn't work, you ask about Y, not X. In this case you assume that X will be solved by changing how you serialize unordered data. What is the actual problem you want to solve? Where does this data come from? A database? Another system? Why not create proper objects to model it and serialize it to XML or JSON?

    – Panagiotis Kanavos
    Nov 20 '18 at 7:47













  • it's coming from an API URL.

    – Iris Lorren Hequibal
    Nov 20 '18 at 8:28











  • Pretty printed the xml.

    – LosManos
    Nov 20 '18 at 9:35



















  • Hi @IrisLorrenHequibal, please, do not repeat your message just to get rid of SO warnings, instead try to provide more information, so that your chances of getting help will be higher!

    – toti08
    Nov 20 '18 at 7:01











  • You already asked the same thing about JSON. This XML schema is actually harder to query than a JSON file. What are you trying to do? Why not use proper elements and attributes instead of dumping a hashtable into unordered XML? A useful XML schema would be <entity><orders/><entityType/></entity>.

    – Panagiotis Kanavos
    Nov 20 '18 at 7:43













  • This sounds like an XY Problem. You have a problem with X and assume the solution is Y. When that doesn't work, you ask about Y, not X. In this case you assume that X will be solved by changing how you serialize unordered data. What is the actual problem you want to solve? Where does this data come from? A database? Another system? Why not create proper objects to model it and serialize it to XML or JSON?

    – Panagiotis Kanavos
    Nov 20 '18 at 7:47













  • it's coming from an API URL.

    – Iris Lorren Hequibal
    Nov 20 '18 at 8:28











  • Pretty printed the xml.

    – LosManos
    Nov 20 '18 at 9:35

















Hi @IrisLorrenHequibal, please, do not repeat your message just to get rid of SO warnings, instead try to provide more information, so that your chances of getting help will be higher!

– toti08
Nov 20 '18 at 7:01





Hi @IrisLorrenHequibal, please, do not repeat your message just to get rid of SO warnings, instead try to provide more information, so that your chances of getting help will be higher!

– toti08
Nov 20 '18 at 7:01













You already asked the same thing about JSON. This XML schema is actually harder to query than a JSON file. What are you trying to do? Why not use proper elements and attributes instead of dumping a hashtable into unordered XML? A useful XML schema would be <entity><orders/><entityType/></entity>.

– Panagiotis Kanavos
Nov 20 '18 at 7:43







You already asked the same thing about JSON. This XML schema is actually harder to query than a JSON file. What are you trying to do? Why not use proper elements and attributes instead of dumping a hashtable into unordered XML? A useful XML schema would be <entity><orders/><entityType/></entity>.

– Panagiotis Kanavos
Nov 20 '18 at 7:43















This sounds like an XY Problem. You have a problem with X and assume the solution is Y. When that doesn't work, you ask about Y, not X. In this case you assume that X will be solved by changing how you serialize unordered data. What is the actual problem you want to solve? Where does this data come from? A database? Another system? Why not create proper objects to model it and serialize it to XML or JSON?

– Panagiotis Kanavos
Nov 20 '18 at 7:47







This sounds like an XY Problem. You have a problem with X and assume the solution is Y. When that doesn't work, you ask about Y, not X. In this case you assume that X will be solved by changing how you serialize unordered data. What is the actual problem you want to solve? Where does this data come from? A database? Another system? Why not create proper objects to model it and serialize it to XML or JSON?

– Panagiotis Kanavos
Nov 20 '18 at 7:47















it's coming from an API URL.

– Iris Lorren Hequibal
Nov 20 '18 at 8:28





it's coming from an API URL.

– Iris Lorren Hequibal
Nov 20 '18 at 8:28













Pretty printed the xml.

– LosManos
Nov 20 '18 at 9:35





Pretty printed the xml.

– LosManos
Nov 20 '18 at 9:35












2 Answers
2






active

oldest

votes


















0














If you already have an XElement root representing the whole tree, you can iterate over the entries:



foreach (var entry in root.Elements("entry")
{
...
}


Each entry seems to have two sub-elements: one <string>key</string> and another <type>...</type> (where type can be string or hashtable).



To get the key string, you could use



var key = entry.Elements().First().Value;


For the value, you have to discriminate according to the element name:



var valueElement = entry.Elements().ElementAt(1);
if (valueElement.Name == "string")
{
var value = valueElement.Value;
}
else if (valueElement == "hashtable")
{
// here, you have to recurse with valueElement instead of root
}


EDIT: Shorter way to get only value of orders.orderid:



var orderIdElement = root.Descendants("entry").FirstOrDefault(_ => _.Elements().First().Value == "orders.orderid");
var orderId = orderIdElement .Elements().ElementAt(1).Value;





share|improve this answer


























  • but my question is how will I only get the content of orders.orderid and entity.description on the XML data I provided?

    – Iris Lorren Hequibal
    Nov 20 '18 at 7:33











  • Added this special case to my answer.

    – Klaus Gütter
    Nov 20 '18 at 7:38



















0














You can use below function to fetch specific sibling element text.



public string ExtractNodeValue(XDocument doc, string search)
{
var result = doc.Descendants("entry")
.Where(x => x.Elements().ElementAt(0).Value == search)
.Select(i => (string)i.Elements().ElementAt(1).Value)
.FirstOrDefault();

return result;
}


And you can use above function like



XDocument doc = XDocument.Load(@"Url to xml file");

string orderId = ExtractNodeValue(doc, "orders.orderid");
string description = ExtractNodeValue(doc, "entity.description");

string output = "orders.orderid: " + orderId + "nentity.description: " + description;


Output from Debugger:



enter image description here






share|improve this answer
























  • Hi, I tried your code but ExtractNodeValue can't be recognized in string orderID and string description.

    – Iris Lorren Hequibal
    Nov 20 '18 at 10:38











  • @IrisLorrenHequibal, this is an exception? then please paste exception message so I'll try to resolve it

    – er-sho
    Nov 20 '18 at 10:41













  • it's working now. thank you :)

    – Iris Lorren Hequibal
    Nov 20 '18 at 10:43











  • @IrisLorrenHequibal, If answer was help you then mark the tick on left side of answer to make it green :)

    – er-sho
    Nov 20 '18 at 10:45











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387495%2fget-specific-xml-data-using-c-sharp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If you already have an XElement root representing the whole tree, you can iterate over the entries:



foreach (var entry in root.Elements("entry")
{
...
}


Each entry seems to have two sub-elements: one <string>key</string> and another <type>...</type> (where type can be string or hashtable).



To get the key string, you could use



var key = entry.Elements().First().Value;


For the value, you have to discriminate according to the element name:



var valueElement = entry.Elements().ElementAt(1);
if (valueElement.Name == "string")
{
var value = valueElement.Value;
}
else if (valueElement == "hashtable")
{
// here, you have to recurse with valueElement instead of root
}


EDIT: Shorter way to get only value of orders.orderid:



var orderIdElement = root.Descendants("entry").FirstOrDefault(_ => _.Elements().First().Value == "orders.orderid");
var orderId = orderIdElement .Elements().ElementAt(1).Value;





share|improve this answer


























  • but my question is how will I only get the content of orders.orderid and entity.description on the XML data I provided?

    – Iris Lorren Hequibal
    Nov 20 '18 at 7:33











  • Added this special case to my answer.

    – Klaus Gütter
    Nov 20 '18 at 7:38
















0














If you already have an XElement root representing the whole tree, you can iterate over the entries:



foreach (var entry in root.Elements("entry")
{
...
}


Each entry seems to have two sub-elements: one <string>key</string> and another <type>...</type> (where type can be string or hashtable).



To get the key string, you could use



var key = entry.Elements().First().Value;


For the value, you have to discriminate according to the element name:



var valueElement = entry.Elements().ElementAt(1);
if (valueElement.Name == "string")
{
var value = valueElement.Value;
}
else if (valueElement == "hashtable")
{
// here, you have to recurse with valueElement instead of root
}


EDIT: Shorter way to get only value of orders.orderid:



var orderIdElement = root.Descendants("entry").FirstOrDefault(_ => _.Elements().First().Value == "orders.orderid");
var orderId = orderIdElement .Elements().ElementAt(1).Value;





share|improve this answer


























  • but my question is how will I only get the content of orders.orderid and entity.description on the XML data I provided?

    – Iris Lorren Hequibal
    Nov 20 '18 at 7:33











  • Added this special case to my answer.

    – Klaus Gütter
    Nov 20 '18 at 7:38














0












0








0







If you already have an XElement root representing the whole tree, you can iterate over the entries:



foreach (var entry in root.Elements("entry")
{
...
}


Each entry seems to have two sub-elements: one <string>key</string> and another <type>...</type> (where type can be string or hashtable).



To get the key string, you could use



var key = entry.Elements().First().Value;


For the value, you have to discriminate according to the element name:



var valueElement = entry.Elements().ElementAt(1);
if (valueElement.Name == "string")
{
var value = valueElement.Value;
}
else if (valueElement == "hashtable")
{
// here, you have to recurse with valueElement instead of root
}


EDIT: Shorter way to get only value of orders.orderid:



var orderIdElement = root.Descendants("entry").FirstOrDefault(_ => _.Elements().First().Value == "orders.orderid");
var orderId = orderIdElement .Elements().ElementAt(1).Value;





share|improve this answer















If you already have an XElement root representing the whole tree, you can iterate over the entries:



foreach (var entry in root.Elements("entry")
{
...
}


Each entry seems to have two sub-elements: one <string>key</string> and another <type>...</type> (where type can be string or hashtable).



To get the key string, you could use



var key = entry.Elements().First().Value;


For the value, you have to discriminate according to the element name:



var valueElement = entry.Elements().ElementAt(1);
if (valueElement.Name == "string")
{
var value = valueElement.Value;
}
else if (valueElement == "hashtable")
{
// here, you have to recurse with valueElement instead of root
}


EDIT: Shorter way to get only value of orders.orderid:



var orderIdElement = root.Descendants("entry").FirstOrDefault(_ => _.Elements().First().Value == "orders.orderid");
var orderId = orderIdElement .Elements().ElementAt(1).Value;






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 7:37

























answered Nov 20 '18 at 6:49









Klaus GütterKlaus Gütter

2,51821321




2,51821321













  • but my question is how will I only get the content of orders.orderid and entity.description on the XML data I provided?

    – Iris Lorren Hequibal
    Nov 20 '18 at 7:33











  • Added this special case to my answer.

    – Klaus Gütter
    Nov 20 '18 at 7:38



















  • but my question is how will I only get the content of orders.orderid and entity.description on the XML data I provided?

    – Iris Lorren Hequibal
    Nov 20 '18 at 7:33











  • Added this special case to my answer.

    – Klaus Gütter
    Nov 20 '18 at 7:38

















but my question is how will I only get the content of orders.orderid and entity.description on the XML data I provided?

– Iris Lorren Hequibal
Nov 20 '18 at 7:33





but my question is how will I only get the content of orders.orderid and entity.description on the XML data I provided?

– Iris Lorren Hequibal
Nov 20 '18 at 7:33













Added this special case to my answer.

– Klaus Gütter
Nov 20 '18 at 7:38





Added this special case to my answer.

– Klaus Gütter
Nov 20 '18 at 7:38













0














You can use below function to fetch specific sibling element text.



public string ExtractNodeValue(XDocument doc, string search)
{
var result = doc.Descendants("entry")
.Where(x => x.Elements().ElementAt(0).Value == search)
.Select(i => (string)i.Elements().ElementAt(1).Value)
.FirstOrDefault();

return result;
}


And you can use above function like



XDocument doc = XDocument.Load(@"Url to xml file");

string orderId = ExtractNodeValue(doc, "orders.orderid");
string description = ExtractNodeValue(doc, "entity.description");

string output = "orders.orderid: " + orderId + "nentity.description: " + description;


Output from Debugger:



enter image description here






share|improve this answer
























  • Hi, I tried your code but ExtractNodeValue can't be recognized in string orderID and string description.

    – Iris Lorren Hequibal
    Nov 20 '18 at 10:38











  • @IrisLorrenHequibal, this is an exception? then please paste exception message so I'll try to resolve it

    – er-sho
    Nov 20 '18 at 10:41













  • it's working now. thank you :)

    – Iris Lorren Hequibal
    Nov 20 '18 at 10:43











  • @IrisLorrenHequibal, If answer was help you then mark the tick on left side of answer to make it green :)

    – er-sho
    Nov 20 '18 at 10:45
















0














You can use below function to fetch specific sibling element text.



public string ExtractNodeValue(XDocument doc, string search)
{
var result = doc.Descendants("entry")
.Where(x => x.Elements().ElementAt(0).Value == search)
.Select(i => (string)i.Elements().ElementAt(1).Value)
.FirstOrDefault();

return result;
}


And you can use above function like



XDocument doc = XDocument.Load(@"Url to xml file");

string orderId = ExtractNodeValue(doc, "orders.orderid");
string description = ExtractNodeValue(doc, "entity.description");

string output = "orders.orderid: " + orderId + "nentity.description: " + description;


Output from Debugger:



enter image description here






share|improve this answer
























  • Hi, I tried your code but ExtractNodeValue can't be recognized in string orderID and string description.

    – Iris Lorren Hequibal
    Nov 20 '18 at 10:38











  • @IrisLorrenHequibal, this is an exception? then please paste exception message so I'll try to resolve it

    – er-sho
    Nov 20 '18 at 10:41













  • it's working now. thank you :)

    – Iris Lorren Hequibal
    Nov 20 '18 at 10:43











  • @IrisLorrenHequibal, If answer was help you then mark the tick on left side of answer to make it green :)

    – er-sho
    Nov 20 '18 at 10:45














0












0








0







You can use below function to fetch specific sibling element text.



public string ExtractNodeValue(XDocument doc, string search)
{
var result = doc.Descendants("entry")
.Where(x => x.Elements().ElementAt(0).Value == search)
.Select(i => (string)i.Elements().ElementAt(1).Value)
.FirstOrDefault();

return result;
}


And you can use above function like



XDocument doc = XDocument.Load(@"Url to xml file");

string orderId = ExtractNodeValue(doc, "orders.orderid");
string description = ExtractNodeValue(doc, "entity.description");

string output = "orders.orderid: " + orderId + "nentity.description: " + description;


Output from Debugger:



enter image description here






share|improve this answer













You can use below function to fetch specific sibling element text.



public string ExtractNodeValue(XDocument doc, string search)
{
var result = doc.Descendants("entry")
.Where(x => x.Elements().ElementAt(0).Value == search)
.Select(i => (string)i.Elements().ElementAt(1).Value)
.FirstOrDefault();

return result;
}


And you can use above function like



XDocument doc = XDocument.Load(@"Url to xml file");

string orderId = ExtractNodeValue(doc, "orders.orderid");
string description = ExtractNodeValue(doc, "entity.description");

string output = "orders.orderid: " + orderId + "nentity.description: " + description;


Output from Debugger:



enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 10:00









er-shoer-sho

6,0672617




6,0672617













  • Hi, I tried your code but ExtractNodeValue can't be recognized in string orderID and string description.

    – Iris Lorren Hequibal
    Nov 20 '18 at 10:38











  • @IrisLorrenHequibal, this is an exception? then please paste exception message so I'll try to resolve it

    – er-sho
    Nov 20 '18 at 10:41













  • it's working now. thank you :)

    – Iris Lorren Hequibal
    Nov 20 '18 at 10:43











  • @IrisLorrenHequibal, If answer was help you then mark the tick on left side of answer to make it green :)

    – er-sho
    Nov 20 '18 at 10:45



















  • Hi, I tried your code but ExtractNodeValue can't be recognized in string orderID and string description.

    – Iris Lorren Hequibal
    Nov 20 '18 at 10:38











  • @IrisLorrenHequibal, this is an exception? then please paste exception message so I'll try to resolve it

    – er-sho
    Nov 20 '18 at 10:41













  • it's working now. thank you :)

    – Iris Lorren Hequibal
    Nov 20 '18 at 10:43











  • @IrisLorrenHequibal, If answer was help you then mark the tick on left side of answer to make it green :)

    – er-sho
    Nov 20 '18 at 10:45

















Hi, I tried your code but ExtractNodeValue can't be recognized in string orderID and string description.

– Iris Lorren Hequibal
Nov 20 '18 at 10:38





Hi, I tried your code but ExtractNodeValue can't be recognized in string orderID and string description.

– Iris Lorren Hequibal
Nov 20 '18 at 10:38













@IrisLorrenHequibal, this is an exception? then please paste exception message so I'll try to resolve it

– er-sho
Nov 20 '18 at 10:41







@IrisLorrenHequibal, this is an exception? then please paste exception message so I'll try to resolve it

– er-sho
Nov 20 '18 at 10:41















it's working now. thank you :)

– Iris Lorren Hequibal
Nov 20 '18 at 10:43





it's working now. thank you :)

– Iris Lorren Hequibal
Nov 20 '18 at 10:43













@IrisLorrenHequibal, If answer was help you then mark the tick on left side of answer to make it green :)

– er-sho
Nov 20 '18 at 10:45





@IrisLorrenHequibal, If answer was help you then mark the tick on left side of answer to make it green :)

– er-sho
Nov 20 '18 at 10:45


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387495%2fget-specific-xml-data-using-c-sharp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?