I am using the C# Yaml Parser mentioned on Code Project Site
If my Yaml looks like the following
- id: tagid
tag:
- name: tagname
value: tagvalue
After it has been successfully parsed, how do I access the Data Items so that I can do some further processing. For example if I need to get the value of "name" what code would I need to write, the document says use doc.Root but can't find any examples on how to use it.
I figured out how to use doc.Root
The doc.Root returns a Mapping after it has parsed the YAML input. I recursively parse that Mapping to check if any of the Data Items are Mapping or Sequence and then act accordingly.
It's a bit naive method but so long as it works.
Many Thanks
Related
I am working with a vendor supplied application that stores XML data as byte array in a SQL database table. I have found if the XML data is "too long" (meaning by a possible predetermined length in black box code provided by the vendor) the XML is truncated and a second record, containing the remainder of the XML data, is created.
My task is to take these "linked" records and merge them into one valid XML string. These linked records can be broken off anywhere, in the middle of an element, node, etc. There is no rhyme or reason to where the XML string is broken.
Taking the invalid XML data and loading it into an XElement causes an error "Tag has no closing tag".
I've also tried using an XmlReader and reading through each Node, based on this article as well as this msdn article. They also result in the above missing tag error.
Is there a way to take these partial xml strings and merge them? Or am I simply stuck?
The vendor application we use does perform this merge, but that code is hidden from me.
Thank you
I want to read through a xaml file, and find all the lines with 'Annotation.AnnotationText' and get specific data from that line.For example, this line:
<prwab:Branch Condition="{x:Null}" sap2010:Annotation.AnnotationText="testing information " ContinuouslyExecute="False" CreatedBy="System Administrator" CreatedOn="2013-02-23T14:51:28.1555955-05:00" DisplayName="Failure" EnableValidationRule="False" sap:VirtualizedContainerService.HintSize="160,234" ID="ab91dec8-1976-491e-91eb-58e073a69d16" IsReportable="False" LastModifiedBy="System Administrator" LastModifiedOn="2013-02-23T14:51:28.1555955-05:00" MediaRecord="[MediaRecord]" SystemName="CollectDigitsActivity1 Failure6" Timeout="10000" Type="Voice">
I want find all the lines with 'AnnotationText' in my xaml file, and get information like text = 'testing information', id = 'ab91dec8-1976-491e-91eb-58e073a69d16' , created date and lastmodified date.
I have 0 knowledge in this area and I don't know where to start and which method should I use. Thanks for helping!
XAML is just a specific flavour of XML. You will need to use XML parsing to read the file into an object that you can process in this manner. I recommend Linq to XML for this (look at XDocument class to get started), specifically as finding values by XName using a specific namespace as you will need to for the "sap2010" namespace is very easy.
You can then easily parse and extract the information you are looking for using those classes.
I made a form that basically displays information about different vendors from an XML file that I was given. The XML file is retrieved from a class that I created, called VendorsDB.cs. On my form, I have a Previous and Next button that I want to display the next vendor or the previous vendor (Vendor1, Vendor2...) but I have no idea what method to use. I know I have to use a loop but I'm not sure as to how to code the loop. I've just started programming with C# so I'm really lost. Any help would be greatly appreciated!
Your question is missing alot of information, but what im seeing is that you need to do some work with XML.
I suggest you look into Linq To XML which enabled you to query tags and attributes with query syntax.
A very simple query good look like this:
// Load the xml from the specified path
var xml = XDocument.Load(#"LocationOfXml");
// Query the first element with a "MyXmlTag" as name
var someAttribute = xml.Descendants().FirstOrDefault(x => x.Name == "MyXmlTag");
The query language is far richer than this simple query. Read up and im sure you'll be able to get it working asap.
i have a yaml file that contains data related to particular device. i want to search for nodes, key/value pairs and retrieve values and then write them to oracle database. how to do that? here is examle:
---
-device:
-printers:
location: 176.12.43.11
description: hp printer
i want to retrieve that data with similar below c# code:
YamlNode node = YamlNode.FromFile("C:\\test\\test.yaml");
YamlMapping mapping = new YamlMapping("device.printers.location");
var value = mapping.Value;
i've already searched for solutions, but didn't find any, there is not much info and detailed documentation about yaml.net . ahh yes, i wan't to retrive data to c# app.
there is .net library for yaml, that seems less documented and i didn't find solution to my problem. thanks in advance
If an ASP.NET form has an XmlDataSource on it, and in code I am setting the XPath filter, e.g:
xmlExample.XPath =
String.Format("data/reasons/reason[#text='{0}']/details/",someValue);
... can I then get the result of that XPath filtering in code, or do I have to bind to a control to find out the results?
In other words, is it possible to use code to access the xml data that an XmlDataSource is going to return?
I haven't actually tried it, but the documentation for XmlDataSource.GetXmlDocument (new with .NET 2.0) suggests it will do exactly what you want:
Return Value
An XmlDataDocument that represents the XML specified in the Data property or in the file identified by the DataFile property, with any transformations and XPath queries applied.