Retrieve value from XML directly [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to know if it is possible to extract and element from a XML in the following fashion. I have tried multiple options such as LinqToXMl and XPath.
<Paper>
<HeaderText>
StackOverFlow
</HeaderText>
</Paper>
For the above XML, if my input is "HeaderText" (the element to be retrieved).
How can I do that without accessing the root element?
Thank You!

XPath has a double-slash which looks anywhere:
//HeaderText/text()
That will return Stack Overflow.

I used the following code to get this working.
XmlDocument document = new XmlDocument();
document.LoadXml(requestXmlString);
XmlNodeList nodes = document.DocumentElement.SelectNodes("//HeaderText");

Related

Returning a list of objects from a function to a text file C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a big function that returns a list of objects. I basically need the results to be put in to a text file. The list contains objects of a class with attributes string Index and integer count. I would want it to be written in a textfile like:
Index : Count fe.
BOOK_FROM_STORE : 27
Anybody has some guidance?
Parse the data held by your object to string and then write it to a text file.

C# how to get diagram name of element - Enterprise Architect [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I need to get diagram`s name of specific elements. Is it possible ?
I added elements note with specific stereotypu using profile to EA project. Then i want create a plugin where i find this notes and diagram names where they are located. (i want export notes and diagram names to excel)....PS: Sorry for my bad english
Issue a SQL like
Repository.SQLQuery("SELECT t_diagram.name FROM t_diagramobjects AS dobj INNER JOIN t_diagram ON dobj.diagram_id = t_diagram.diagram_id WHERE t_diagramobjects.Object_ID = <elementID>"
Just replace <elementID> with the element's elementID. You could alternatively retrieve the diagram GUID (t_diagram.ea_guid') and get the diagram details viaRepostory.GetDiagramByGUID`.

using SQL SERVER can create xml Document like [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
IN SQL SERVER can create XML Document like following format with every column name come with Datafield FieldName="Batch"
CID,BATCH,EXP_DATE are column names.
enter image description here
Try something like
SELECT 'BATCH' AS [DataField/#fieldName]
,BATCH AS [DataField]
,''
,'EXP_DATE' AS [DataField/#fieldName]
,EXP_Date AS [DataField]
FROM SomeWhere
FOR XML PATH('Memory');
The empty string in the middle is needed to start a new element
And be aware, that the dateformat will be ISO8601 and not 190615 (you should be happy about this!)
If you want to achieve XML document creation from C#, then it can be achieved through ADO.net with Help of DataSet. Method name is DataSet.WriteXml(string Filename).

How c# asp.net read by separate between xml and string in xml node? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I got result from some system and don't know how to read by separate btw xml and string as below example.
<result>
<xmldataHeader>
<HeaderId>1</HeaderId>
<xmldataDetail>
<DetailId>1</DetailId>
<DetailName>test</DetailName>
</xmldataDetail>
</xmldataHeader>success
</result>
expected result, it can read "success" or only xml in <result></result>
Thanks in advance.
If your XML structure remains almost static as given in this question, you will be able to access the "success" text with doc.SelectSingleNode("result").LastChild.OuterXml);Please find the sample code below.
XmlDocument doc = new XmlDocument();
doc.LoadXml($#"
<result>
<xmldataHeader>
<HeaderId> 1 </HeaderId>
<xmldataDetail>
<DetailId> 1 </DetailId>
<DetailName> test </DetailName>
</xmldataDetail>
</xmldataHeader> success
</result>");
Console.WriteLine("Succes :" + doc.SelectSingleNode("result").LastChild.OuterXml);
Console.WriteLine("xmldataHeader :"+doc.SelectSingleNode("result").FirstChild.OuterXml);
I dont totally understand your question. But if you want to separate all tags and get the individual data, you'll have to parse the xml.
One example is by using XmlReader in C#.
https://msdn.microsoft.com/en-us/library/cc189056(v=vs.95).aspx

Can I create a Request object by a URL? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a URL, such as http://www.mydomain.com/?param1=asd2&param2=asd2.
I'd like to create a sort of Frequest object, so than I can easily do somethings like:
Request.Querystring("param1")
without do a further Split and access to the array. Can I?
Your question is not clear. Are you looking something like this?
var uri = new Uri("http://www.mydomain.com/?param1=asd2&param2=asd2");
var nv = uri.ParseQueryString();
Console.WriteLine(nv["param1"]);
EDIT
It seams one of my referenced libraries implemented this extension Method. Anyway, it can be done as
var uri = new Uri("http://www.mydomain.com/?param1=asd2&param2=asd2");
var nv = HttpUtility.ParseQueryString(uri.Query);
Console.WriteLine(nv["param1"]);

Categories