xelement

Converting XElement into XmlNode

*爱你&永不变心* 提交于 2019-12-03 23:44:55
I know there is no direct method of doing it but still.. Can we convert XElement element into XmlNode . Options like InnerText and InnerXml are XmlNode specific. so,if i want to use these options, what can be done to convert XElement into XmlNode and vice versa. Here is converting from string to XElement to XmlNode and back to XElement. ToString() on XElement is similar to OuterXml on XmlNode. XElement xE = XElement.Parse("<Outer><Inner><Data /></Inner></Outer>"); XmlDocument xD = new XmlDocument(); xD.LoadXml(xE.ToString()); XmlNode xN = xD.FirstChild; XElement xE2 = XElement.Parse(xN

XElement value in C#

风格不统一 提交于 2019-12-03 12:37:29
How to get a value of XElement without getting child elements? An example: <?xml version="1.0" ?> <someNode> someValue <child>1</child> <child>2</child> </someNode> If i use XElement.Value for <someNode> I get "somevalue<child>1</child><child>2<child>" string but I want to get only "somevalue" without "<child>1</child><child>2<child>" substring. You can do it slightly more simply than using Descendants - the Nodes method only returns the direct child nodes: XElement element = XElement.Parse( @"<someNode>somevalue<child>1</child><child>2</child></someNode>"); var firstTextValue = element.Nodes(

xml parsing - code refactoring issue

こ雲淡風輕ζ 提交于 2019-12-02 22:49:28
问题 I have the following xml: <?xml version="1.0" encoding="utf-8"?> <RootData> <PassResult> <FirstOne>P1</FirstOne> <SecondOne>P2</SecondOne> <IsMale>false</IsMale> </PassResult> <TestResult> <MarkOne>100</MarkOne> <MarkTwo>50</MarkTwo> <Slope>30</Slope> </TestResult> <ToneTestResult> <TotalTime>2</TotalTime> <CorrectPercentage>90</CorrectPercentage> </ToneTestResult> <QuestionnaireResult Version="1"> <Question Id="50"> <Answer Id="B" /> </Question> <Question Id="60"> <Answer Id="A" /> <

Avoid xml escaping of angle brackets, when passing xml string to System.Xml.Linq.XElement

ぃ、小莉子 提交于 2019-12-02 21:29:42
问题 I'm getting a string from string GetXmlString() ; this I cant change. I have to append this to an xml within a new XElement ("parent" , ... ); , to the ... area. This string I'm getting is of the following format. <tag name="" value =""></tag> <tag name="" value =""></tag> <tag name="" value =""></tag> ... The final result I want is this to be like <parent> <tag name="" value =""></tag> <tag name="" value =""></tag> <tag name="" value =""></tag> <tag name="" value =""></tag> <tag name=""

xml parsing - code refactoring issue

浪子不回头ぞ 提交于 2019-12-02 13:15:19
I have the following xml: <?xml version="1.0" encoding="utf-8"?> <RootData> <PassResult> <FirstOne>P1</FirstOne> <SecondOne>P2</SecondOne> <IsMale>false</IsMale> </PassResult> <TestResult> <MarkOne>100</MarkOne> <MarkTwo>50</MarkTwo> <Slope>30</Slope> </TestResult> <ToneTestResult> <TotalTime>2</TotalTime> <CorrectPercentage>90</CorrectPercentage> </ToneTestResult> <QuestionnaireResult Version="1"> <Question Id="50"> <Answer Id="B" /> </Question> <Question Id="60"> <Answer Id="A" /> </Question> </QuestionnaireResult> </RootData> I have the following code which is not at all looking a good one.

How to use Xelement in this situation

爷,独闯天下 提交于 2019-12-02 10:11:26
I have to obtain this kind of xml : <ps> <pr> <name>name1</name> <comp> <type>CB</type> <attr> <value>0</value> </attr> </comp> </pr> <sep>sep1</sep> <pr> <name>name2</name> <comp> <type>RB</type> <attr> <value>1</value> </attr> </comp> </pr> <sep>sep2</sep> <pr> <name>name3</name> <comp> <type>CoM</type> <attr> <value>2</value> </attr> </comp> </pr> <sep>sep3</sep> </ps> You can see that i have ps as parent of all and after that i have pr and sep in a sequence and i want to maintain this sequence. Before i used XmlElement for this but it was showing all sep togetehr and all pr together. I

Avoid xml escaping of angle brackets, when passing xml string to System.Xml.Linq.XElement

跟風遠走 提交于 2019-12-02 08:51:19
I'm getting a string from string GetXmlString() ; this I cant change. I have to append this to an xml within a new XElement ("parent" , ... ); , to the ... area. This string I'm getting is of the following format. <tag name="" value =""></tag> <tag name="" value =""></tag> <tag name="" value =""></tag> ... The final result I want is this to be like <parent> <tag name="" value =""></tag> <tag name="" value =""></tag> <tag name="" value =""></tag> <tag name="" value =""></tag> <tag name="" value =""></tag> ... </parent> when I just pass the string as XElement("root", GetXmlString()) < and > are

How to parse single xml node in windows phone

别等时光非礼了梦想. 提交于 2019-12-02 07:43:20
<root>1234</root> how do I pasrse this single xml node and it comes from web service response, I am using: void webservice_completedeventArgs() { XDocument doc = XDocument.Parse(e.Result); } this code runs very well in Emulator but in device when I debug, I am getting this error: "Data at Root level is invalid" I think its happening due to, There is no XML Dclaration in web service response like "<XML Version 1.0 Encoding UTF-8?>" So how do I parse that single XML node. Please any help would be greatly appreciated 来源: https://stackoverflow.com/questions/22789893/how-to-parse-single-xml-node-in

Is there an XElement equivalent to XmlWriter.WriteRaw?

不羁的心 提交于 2019-12-02 01:59:45
问题 I'm converting some code that currently uses an XmlWriter to create a document to instead return an XElement of the content. So far, I'm enjoying structuring the code in a way that mimics the structure of the document, but there is content that was written using XmlWriter.WriteRaw to avoid re-xmlizing the xml. I can't find any equivalent in the System.Xml.Linq namespace. Does one exist? 回答1: XElement.Parse() should do the trick. For example: XElement e = new XElement("root", new XElement(

How to get specific value from a xml string in c#

泪湿孤枕 提交于 2019-12-02 01:11:54
问题 I have following string <SessionInfo> <SessionID>MSCB2B-UKT3517_f2823910df-5eff81-528aff-11e6f-0d2ed2408332</SessionID> <Profile>A</Profile> <Language>ENG</Language> <Version>1</Version> </SessionInfo> now I want to get the value of SessionID . I tried with below .. var rootElement = XElement.Parse(output);//output means above string and this step has values but in here,, var one = rootElement.Elements("SessionInfo"); it didn't work.what can I do that. and What if the xml string like below