Using dictionary notation to get xml valuesHow do you get the index of the current iteration of a foreach loop?How do I get the path of the assembly the code is in?What is the best way to iterate over a dictionary?Why is Dictionary preferred over Hashtable in C#?String representation of an EnumHow do I get a consistent byte representation of strings in C# without manually specifying an encoding?Get int value from enum in C#get dictionary key by valueHow to read XML using XPath in JavaHow do you parse and process HTML/XML in PHP?
Does an object count as "being moved" when placed in a Bag of Holding before its wielder moves, and then after moving they take the object out again?
Why we don't have vaccination against all diseases which are caused by microbes?
Vacuum collapse -- why do strong metals implode but glass doesn't?
Mathematical uses of string theory
How much code would a codegolf golf if a codegolf could golf code?
Is it possible to create a golf ball sized star?
Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")
What professions would a medieval village with a population of 100 need?
What magic extends life or grants immortality?
How can I watch the 17th (or last, if less) line in files of a folder?
How do I find the fastest route from Heathrow to an address in London using all forms of transport?
Was Switzerland really impossible to invade during WW2?
Is refusing to concede in the face of an unstoppable Nexus combo punishable?
Is a butterfly one or two animals?
Why were movies shot on film shot at 24 frames per second?
Can you feel passing through the sound barrier in an F-16?
How would one country purchase another?
Was Tuvok bluffing when he said that Voyager's transporters rendered the Kazon weapons useless?
Can I switch to third-person while not in 'town' in Destiny 2?
Why does my house heat up, even when it's cool outside?
Does the length of a Scientific report imply anything about credibility or thoroughness?
Check in to 2 hotels at same location
Can you help me understand Modes from the aspect of chord changes?
Why is less being run unnecessarily by git?
Using dictionary notation to get xml values
How do you get the index of the current iteration of a foreach loop?How do I get the path of the assembly the code is in?What is the best way to iterate over a dictionary?Why is Dictionary preferred over Hashtable in C#?String representation of an EnumHow do I get a consistent byte representation of strings in C# without manually specifying an encoding?Get int value from enum in C#get dictionary key by valueHow to read XML using XPath in JavaHow do you parse and process HTML/XML in PHP?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I've got XML, and would like to get the value of a node using array/data table like notation
<Response>
<Outcome>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>Icon</Key>
<Value>
<DataType>System.String</DataType>
<Field>Icon</Field>
<Value>O</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>IconDescription</Key>
<Value>
<DataType>System.String</DataType>
<Field>IconDescription</Field>
<Value>Old</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>IconLongDescription</Key>
<Value>
<DataType>System.String</DataType>
<Field>IconLongDescription</Field>
<Value>Older</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
</Outcome>
</Response>
I want to do something like outcome.Key[IconDescription].Value
to give me a value of "Old"
c# .net xml xpath
add a comment |
I've got XML, and would like to get the value of a node using array/data table like notation
<Response>
<Outcome>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>Icon</Key>
<Value>
<DataType>System.String</DataType>
<Field>Icon</Field>
<Value>O</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>IconDescription</Key>
<Value>
<DataType>System.String</DataType>
<Field>IconDescription</Field>
<Value>Old</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>IconLongDescription</Key>
<Value>
<DataType>System.String</DataType>
<Field>IconLongDescription</Field>
<Value>Older</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
</Outcome>
</Response>
I want to do something like outcome.Key[IconDescription].Value
to give me a value of "Old"
c# .net xml xpath
What language is this referring to? What attempts have you made?
– Pedro Rodrigues
Mar 26 at 10:16
Using c#, I have tried converting the XML to an array to get the data like that, but that failed
– John
Mar 26 at 11:29
What you posted isn't a table-like or dictionary notation. It's something specific to your application. The name of an XML element doesn't specify any kind of behaviour. Just because one element is namedKey
and anotherValue
doesn't mean they are part of a table or dictionary.
– Panagiotis Kanavos
Mar 26 at 11:30
Post the C# code you're having trouble with.
– Pedro Rodrigues
Mar 26 at 11:30
Given how regular this XML is, you can deserialize it to concrete classes and write code that converts them to the form you want. You could use Linq to XML to load the string and transform it too. On the other hand, this schema is rather wasteful. Schema information like the data type should be part of an XSD, not the document itself.Icon
,IconDescription
etc should be attributes or elements.
– Panagiotis Kanavos
Mar 26 at 11:34
add a comment |
I've got XML, and would like to get the value of a node using array/data table like notation
<Response>
<Outcome>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>Icon</Key>
<Value>
<DataType>System.String</DataType>
<Field>Icon</Field>
<Value>O</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>IconDescription</Key>
<Value>
<DataType>System.String</DataType>
<Field>IconDescription</Field>
<Value>Old</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>IconLongDescription</Key>
<Value>
<DataType>System.String</DataType>
<Field>IconLongDescription</Field>
<Value>Older</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
</Outcome>
</Response>
I want to do something like outcome.Key[IconDescription].Value
to give me a value of "Old"
c# .net xml xpath
I've got XML, and would like to get the value of a node using array/data table like notation
<Response>
<Outcome>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>Icon</Key>
<Value>
<DataType>System.String</DataType>
<Field>Icon</Field>
<Value>O</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>IconDescription</Key>
<Value>
<DataType>System.String</DataType>
<Field>IconDescription</Field>
<Value>Old</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
<KeyValueOfstringOutcomepQnxSKQu>
<Key>IconLongDescription</Key>
<Value>
<DataType>System.String</DataType>
<Field>IconLongDescription</Field>
<Value>Older</Value>
</Value>
</KeyValueOfstringOutcomepQnxSKQu>
</Outcome>
</Response>
I want to do something like outcome.Key[IconDescription].Value
to give me a value of "Old"
c# .net xml xpath
c# .net xml xpath
edited Mar 26 at 11:22
John
asked Mar 26 at 9:44
JohnJohn
8810 bronze badges
8810 bronze badges
What language is this referring to? What attempts have you made?
– Pedro Rodrigues
Mar 26 at 10:16
Using c#, I have tried converting the XML to an array to get the data like that, but that failed
– John
Mar 26 at 11:29
What you posted isn't a table-like or dictionary notation. It's something specific to your application. The name of an XML element doesn't specify any kind of behaviour. Just because one element is namedKey
and anotherValue
doesn't mean they are part of a table or dictionary.
– Panagiotis Kanavos
Mar 26 at 11:30
Post the C# code you're having trouble with.
– Pedro Rodrigues
Mar 26 at 11:30
Given how regular this XML is, you can deserialize it to concrete classes and write code that converts them to the form you want. You could use Linq to XML to load the string and transform it too. On the other hand, this schema is rather wasteful. Schema information like the data type should be part of an XSD, not the document itself.Icon
,IconDescription
etc should be attributes or elements.
– Panagiotis Kanavos
Mar 26 at 11:34
add a comment |
What language is this referring to? What attempts have you made?
– Pedro Rodrigues
Mar 26 at 10:16
Using c#, I have tried converting the XML to an array to get the data like that, but that failed
– John
Mar 26 at 11:29
What you posted isn't a table-like or dictionary notation. It's something specific to your application. The name of an XML element doesn't specify any kind of behaviour. Just because one element is namedKey
and anotherValue
doesn't mean they are part of a table or dictionary.
– Panagiotis Kanavos
Mar 26 at 11:30
Post the C# code you're having trouble with.
– Pedro Rodrigues
Mar 26 at 11:30
Given how regular this XML is, you can deserialize it to concrete classes and write code that converts them to the form you want. You could use Linq to XML to load the string and transform it too. On the other hand, this schema is rather wasteful. Schema information like the data type should be part of an XSD, not the document itself.Icon
,IconDescription
etc should be attributes or elements.
– Panagiotis Kanavos
Mar 26 at 11:34
What language is this referring to? What attempts have you made?
– Pedro Rodrigues
Mar 26 at 10:16
What language is this referring to? What attempts have you made?
– Pedro Rodrigues
Mar 26 at 10:16
Using c#, I have tried converting the XML to an array to get the data like that, but that failed
– John
Mar 26 at 11:29
Using c#, I have tried converting the XML to an array to get the data like that, but that failed
– John
Mar 26 at 11:29
What you posted isn't a table-like or dictionary notation. It's something specific to your application. The name of an XML element doesn't specify any kind of behaviour. Just because one element is named
Key
and another Value
doesn't mean they are part of a table or dictionary.– Panagiotis Kanavos
Mar 26 at 11:30
What you posted isn't a table-like or dictionary notation. It's something specific to your application. The name of an XML element doesn't specify any kind of behaviour. Just because one element is named
Key
and another Value
doesn't mean they are part of a table or dictionary.– Panagiotis Kanavos
Mar 26 at 11:30
Post the C# code you're having trouble with.
– Pedro Rodrigues
Mar 26 at 11:30
Post the C# code you're having trouble with.
– Pedro Rodrigues
Mar 26 at 11:30
Given how regular this XML is, you can deserialize it to concrete classes and write code that converts them to the form you want. You could use Linq to XML to load the string and transform it too. On the other hand, this schema is rather wasteful. Schema information like the data type should be part of an XSD, not the document itself.
Icon
, IconDescription
etc should be attributes or elements.– Panagiotis Kanavos
Mar 26 at 11:34
Given how regular this XML is, you can deserialize it to concrete classes and write code that converts them to the form you want. You could use Linq to XML to load the string and transform it too. On the other hand, this schema is rather wasteful. Schema information like the data type should be part of an XSD, not the document itself.
Icon
, IconDescription
etc should be attributes or elements.– Panagiotis Kanavos
Mar 26 at 11:34
add a comment |
1 Answer
1
active
oldest
votes
Linq provides access to XML through the XDocument
class which allows you to run XPath against XML. Whilst it is not exactly in the style of your ideal XPath does provide a handy query language for accessing XML nodes, and your tag suggests you might be interested in an XPath solution!
Here is an example of using an XDocument
to query an XML file. For this example I've simply read a file from a stream.
using System.Xml.Linq;
using System.Xml.XPath;
...
static void Main(string[] args)
XDocument doc = XDocument.Load(new FileStream(@"C:path_toinput.xml", FileMode.Open));
string desrcription = doc.XPathSelectElement("/Response/Outcome/KeyValueOfstringOutcomepQnxSKQu[Key='IconDescription']/Value/Value").Value;
Console.WriteLine(desrcription);
Console.ReadLine();
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353996%2fusing-dictionary-notation-to-get-xml-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Linq provides access to XML through the XDocument
class which allows you to run XPath against XML. Whilst it is not exactly in the style of your ideal XPath does provide a handy query language for accessing XML nodes, and your tag suggests you might be interested in an XPath solution!
Here is an example of using an XDocument
to query an XML file. For this example I've simply read a file from a stream.
using System.Xml.Linq;
using System.Xml.XPath;
...
static void Main(string[] args)
XDocument doc = XDocument.Load(new FileStream(@"C:path_toinput.xml", FileMode.Open));
string desrcription = doc.XPathSelectElement("/Response/Outcome/KeyValueOfstringOutcomepQnxSKQu[Key='IconDescription']/Value/Value").Value;
Console.WriteLine(desrcription);
Console.ReadLine();
add a comment |
Linq provides access to XML through the XDocument
class which allows you to run XPath against XML. Whilst it is not exactly in the style of your ideal XPath does provide a handy query language for accessing XML nodes, and your tag suggests you might be interested in an XPath solution!
Here is an example of using an XDocument
to query an XML file. For this example I've simply read a file from a stream.
using System.Xml.Linq;
using System.Xml.XPath;
...
static void Main(string[] args)
XDocument doc = XDocument.Load(new FileStream(@"C:path_toinput.xml", FileMode.Open));
string desrcription = doc.XPathSelectElement("/Response/Outcome/KeyValueOfstringOutcomepQnxSKQu[Key='IconDescription']/Value/Value").Value;
Console.WriteLine(desrcription);
Console.ReadLine();
add a comment |
Linq provides access to XML through the XDocument
class which allows you to run XPath against XML. Whilst it is not exactly in the style of your ideal XPath does provide a handy query language for accessing XML nodes, and your tag suggests you might be interested in an XPath solution!
Here is an example of using an XDocument
to query an XML file. For this example I've simply read a file from a stream.
using System.Xml.Linq;
using System.Xml.XPath;
...
static void Main(string[] args)
XDocument doc = XDocument.Load(new FileStream(@"C:path_toinput.xml", FileMode.Open));
string desrcription = doc.XPathSelectElement("/Response/Outcome/KeyValueOfstringOutcomepQnxSKQu[Key='IconDescription']/Value/Value").Value;
Console.WriteLine(desrcription);
Console.ReadLine();
Linq provides access to XML through the XDocument
class which allows you to run XPath against XML. Whilst it is not exactly in the style of your ideal XPath does provide a handy query language for accessing XML nodes, and your tag suggests you might be interested in an XPath solution!
Here is an example of using an XDocument
to query an XML file. For this example I've simply read a file from a stream.
using System.Xml.Linq;
using System.Xml.XPath;
...
static void Main(string[] args)
XDocument doc = XDocument.Load(new FileStream(@"C:path_toinput.xml", FileMode.Open));
string desrcription = doc.XPathSelectElement("/Response/Outcome/KeyValueOfstringOutcomepQnxSKQu[Key='IconDescription']/Value/Value").Value;
Console.WriteLine(desrcription);
Console.ReadLine();
answered Mar 27 at 16:25
Dan GardnerDan Gardner
2133 silver badges14 bronze badges
2133 silver badges14 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353996%2fusing-dictionary-notation-to-get-xml-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What language is this referring to? What attempts have you made?
– Pedro Rodrigues
Mar 26 at 10:16
Using c#, I have tried converting the XML to an array to get the data like that, but that failed
– John
Mar 26 at 11:29
What you posted isn't a table-like or dictionary notation. It's something specific to your application. The name of an XML element doesn't specify any kind of behaviour. Just because one element is named
Key
and anotherValue
doesn't mean they are part of a table or dictionary.– Panagiotis Kanavos
Mar 26 at 11:30
Post the C# code you're having trouble with.
– Pedro Rodrigues
Mar 26 at 11:30
Given how regular this XML is, you can deserialize it to concrete classes and write code that converts them to the form you want. You could use Linq to XML to load the string and transform it too. On the other hand, this schema is rather wasteful. Schema information like the data type should be part of an XSD, not the document itself.
Icon
,IconDescription
etc should be attributes or elements.– Panagiotis Kanavos
Mar 26 at 11:34