linq-to-xml

Encoding problems with XDocument XElement when using ReplaceWith method

大城市里の小女人 提交于 2020-01-11 13:22:10
问题 I have the following code: XDocument doc = XDocument.Load(file); var x = doc.Descendants("span"); XElement xelm = x.FirstOrDefault(xm => xm.Attribute("class").Value=="screenitems"); Regex rgx = new Regex("^<span class=\"screenitems\">(.*)</span>$"); Match mtc = rgx.Match(xelm.Value); if (mtc.Success) { xelm.ReplaceWith(mtc.Groups[1].Value); } doc.Save(file); When I get a match and replace the content of the XML file loaded into variable doc using the ReplaceWith method for the XElement

“The ':' character, hexadecimal value 0x3A, cannot be included in a name”

依然范特西╮ 提交于 2020-01-11 08:36:11
问题 I have a code which will read some xml file(s). I tried different ways to solve this problem, but couldn't. Also I tried to code like this: Namespace my = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-01-11T08:31:30"; XElement myEgitimBilgileri = XDocument.Load(@"C:\25036077.xml").Element("my:"+ "Egitim_Bilgileri"); But all the time the same mistake. Here is the original: private void button2_Click(object sender, EventArgs e) { XElement myEgitimBilgileri = XDocument.Load(@"C:

Parsing inner tag with its value

守給你的承諾、 提交于 2020-01-10 05:47:05
问题 I have a plist in this format: <plist version="1.0"> <array> <dict> <key>Title</key> <string>Chapters</string> <key>Items</key> <array> <dict> <key>Title</key> <string>XYZ</string> </dict> <dict> <key>Title</key> <string>ABC</string> </dict> </array> </dict> <dict> <key>Title</key> <string>ChaptersONE</string> <key>Items</key> <array> <dict> <key>Title</key> <string>ASDF</string> </dict> </array> </dict> </array> I have a Class Chapters class with String and List : i need it like this:

How to remove xmlns attribute of a node other than root in an XDocument?

这一生的挚爱 提交于 2020-01-10 02:28:16
问题 Situation I'm using XDocument to try and remove an xmlns="" attribute on the first inner node: <Root xmlns="http://my.namespace"> <Firstelement xmlns=""> <RestOfTheDocument /> </Firstelement> </Root> So what I want as a result is: <Root xmlns="http://my.namespace"> <Firstelement> <RestOfTheDocument /> </Firstelement> </Root> Code doc = XDocument.Load(XmlReader.Create(inStream)); XElement inner = doc.XPathSelectElement("/*/*[1]"); if (inner != null) { inner.Attribute("xmlns").Remove(); }

Find Elements by Attribute using XDocument

耗尽温柔 提交于 2020-01-09 19:21:14
问题 This query seems to be valid, but I have 0 results. IEnumerable<XElement> users = (from el in XMLDoc.Elements("Users") where (string)el.Attribute("GUID") == userGUID.ToString() select el); My XML is as follows: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Users> <User GUID="68327fe2-d6f0-403b-a7b6-51860fbf0b2f"> <Key ID="F7000012ECEAD101"> ... </Key> </User> </Users> Do you have any clues to shed some light onto this? 回答1: change Users in the 2nd line to User . Like this:

How to use XDocument class in Mono

给你一囗甜甜゛ 提交于 2020-01-07 08:47:13
问题 I'm trying to use XDocument class inside a Unity3D project on Windows 7 . I did the following: added the reference System.Xml.Linq to the Mono project. included the namespace: using System.Xml.Linq; set the target framework to: Mono/.NET 3.5 clean and rebuild the project But still Unity3D complains about it. Here's the error output in the console: Assets/Scripts/Editor/RoadManager/RoadManager.cs(3,18): error CS0234: The type or namespace name `Linq' does not exist in the namespace `System.Xml

Why doesn't this code find any duplicates within an xml element?

不问归期 提交于 2020-01-07 05:19:44
问题 Here is the input xml: <?xml version="1.0"?> <StateSeparationRequestCollection xsi:schemaLocation="https://uidataexchange.org/schemas SeparationRequest.xsd" xmlns="https://uidataexchange.org/schemas" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <StateSeparationRequest> <StateRequestRecordGUID>30000000000000000000000000004000</StateRequestRecordGUID> <SSN>999999999</SSN> </StateSeparationRequest> <StateSeparationRequest> <StateRequestRecordGUID>30000000000000000000000000004000<

How to parse deeply nested using LINQ to XML

倾然丶 夕夏残阳落幕 提交于 2020-01-07 05:02:08
问题 How do I parse the following XML using LINQ? I need to insert into a database table OrderNumber, ShipAddress, ShipCity, ShipState for each Order & OrderCancelled . Then in a separate table I need to insert OrderId from the Returns/Amount section. <!-- language: lang-xml --> <?xml version="1.0" encoding="utf-8"?> <OrdersReport Date="2012-08-01"> <Client> <ClientId>1</ClientId> <Orders> <Order> <OrderNumber>1</OrderNumber> <ShipAddress>123 Main St.</ShipAddress> <ShipCity>MyCity</ShipCity>

C# xdocument read from element and put the value into string

混江龙づ霸主 提交于 2020-01-07 03:07:36
问题 I have a problem. This is the first time i work with a xml document in c# I have a XML document like this: <root> <GLOBAL> <copy>@srcdir@c:\test1\test.txt, @destdir@C:\test1\test.txt</copy> </GLOBAL> </root> Now i want to make an application in c# that loads the xml (done using xdocument), you chose an option (in this case global) and then it gets the copy element, and copie's the files listed in this element. I have the copy function working, loading the xml is done, but getting the srcdir

Create xml format c# [closed]

半城伤御伤魂 提交于 2020-01-06 20:00:50
问题 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 . I want to make xml format like this in c# <?xml version='1.0' encoding='us-ascii'?> <root> <key value="22.wav"> <Index>1</Index> <Index>20</Index> <Index>21</Index> </key> <key value="EFG.wav"> <Index>5</Index> <Index>22</Index> </key> </root> How do i form like this please help me 回答1: You could