linq-to-xml

Does LINQ to XML ignore includes from a DTD?

走远了吗. 提交于 2019-12-11 04:36:46
问题 I'm using the MathML DTD for parsing MathML using System.Xml.Linq. While the ordinary MathML stuff gets recognized fine, the MMLEXTRA include in the DTD gets ignored and I get errors. Here's the code I'm using: if (!string.IsNullOrWhiteSpace(mathML)) { try { const string preamble = "<!DOCTYPE mml:math PUBLIC \"-//W3C//DTD MathML 2.0//EN\"\n" + "\"http://www.w3.org/Math/DTD/mathml2/mathml2.dtd\" [\n" + "<!ENTITY % MATHML.prefixed \"INCLUDE\">\n" + "<!ENTITY % MATHML.prefix \"mml\"> \n" + "]>";

How to swap two XML elements in linq to xml

江枫思渺然 提交于 2019-12-11 04:09:52
问题 I want to swap two xml elements. How do i do this? Here is the code. I tried the solution here but it did not work for me after all. I want to swap the both elements. When I run the program the elements are not swapped but when I call ToList() it is swapped in the List but not swapped in the doc variable <template id="12"> <tabs> <tab> <name>test1</name> <description /> </tab> <tab> <name>test2</name> <description /> </tab> </tabs> </template> Here is the code to swap them var doc = XDocument

LINQ to XML: how to get collection of all attributes from all elements

坚强是说给别人听的谎言 提交于 2019-12-11 03:39:21
问题 I have some XML like this: <Section xmlns=\"http:schemas.microsoft.com/winfx/2006/xaml/presentation\"> <Paragraph FontSize=\"12\" FontFamily=\"Arial\" Foreground=\"#FF000000\" FontWeight=\"Normal\" FontStyle=\"Normal\" FontStretch=\"Normal\" TextAlignment=\"Left\"> <Run FontWeight=\"Normal\" Text=\"space \" /> </Paragraph> </Section> Is there a way to get a collection of all the FontWeight attributes, all the FontSize attributes, etc., regardless of the parent element? 回答1: Assuming you have

XElement.GetSchemaInfo() is returning null, Why?

爱⌒轻易说出口 提交于 2019-12-11 03:36:05
问题 I'm trying to validate an XDocument with a compiled schema that I have (which works) but when I try to access PSVI for the root XElement it returns null. I need this so I can validate child XElements. Here is a sample code of what I'm trying to do: XDocument xmlDoc = XDocument.Load(xmlFilePath); XElement root = _xmlDoc.Elements().Single(); XmlSchemaSet schemas = new XmlSchemaSet(); schemas.Add(schema); xmlDoc.Validate(schemas, ValidationEventHandler); XmlSchemaElement se = xmlDoc.Elements()

Unity3d and System.Xml.Linq

对着背影说爱祢 提交于 2019-12-11 03:19:01
问题 So even though the Unity\Editor\Data\Mono\lib\mono\2.0\System.Xml.Linq.dll file exists, doing: using System.Xml.Linq; generates the following error: "The type or namespace name 'Linq' does not exist in the namespace 'System.Xml'. What can I do to implement this? 回答1: You also need to reference the Namespace by right clicking References and selecting the namespace. 回答2: I know this post is a little old but I thought this may perhaps help someone coming across this post. If you want to add a

Locking XML file in Web Application

拥有回忆 提交于 2019-12-11 03:06:28
问题 We have a website application which acts as a form designer. The form data is stored in XML file. Each form has it's own xml file. When i edit a form, i basically recreate the XML file. public void Save(Guid form_Id, IEnumerable<FormData> formData) { XDocument doc = new XDocument(); XElement formsDataElement = new XElement("FormsData"); doc.Add(formsDataElement); foreach (FormData data in formData) { formsDataElement.Add(new XElement("FormData", new XAttribute("Id", data.Id) new XAttribute(

Adding new XElement appends entire XML file to existing file when saved

北城余情 提交于 2019-12-11 02:28:40
问题 I am created a new xml document if one isn't found, then opening it to create a new entry. However it just seems to be appending a completed new XML file to end of the blank file I created after creation: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Devices /> after adding new xelement: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Devices /><?xml version="1.0" encoding="utf-8" standalone="yes"?> <Devices> <device> <name>blah</name> <src00>True</src00> </device> <

Linq to Xml is printing only first descendant value

萝らか妹 提交于 2019-12-11 01:56:56
问题 The following code is printing Building Phone but not printing uxPhone . 1) Should I be getting a collection of Property descendants maybe? 2) This seems pretty verbose, is there a shorter form of doing this? var xmlstr = @"<Form> <ControlsLayout> <Object type='sometype' children='Controls'> <Property name='ControlLabel'>BuildingPhone</Property> <Property name='Name'>uxPhone</Property> </Object> </ControlsLayout> </Form>"; XElement xelement = XElement.Parse(xmlstr); var controls = xelement

Stuck on basic Linq to XML query

限于喜欢 提交于 2019-12-11 00:06:33
问题 I'm trying to extract the information from the namecheap sandbox api and can't figure out why my linq queries aren't working. Here's a sample response. XML <ApiResponse Status="OK" xmlns="http://api.namecheap.com/xml.response"> <Errors /> <Warnings /> <RequestedCommand>namecheap.domains.check</RequestedCommand> <CommandResponse> <DomainCheckResult Domain="google.com" Available="false" /> </CommandResponse> <Server>WEB1-SANDBOX1</Server> <GMTTimeDifference>--4:00</GMTTimeDifference>

XDocument.Load(feedUrl) returns “Data at the root level is invalid. Line 1, position 1.”

天大地大妈咪最大 提交于 2019-12-10 23:51:46
问题 first of all, this is more of a solution, than a question. It took me a while to resolve, so I thought my resolution might worth sharing. I was trying to load an RSS feed using XDoument.Load(feedUrl) and was getting the above Exception. I checked the feed itself in my browser and the format looked fine. So after finding some similar situations here: Meaning of - <?xml version="1.0" encoding="utf-8"?> Why "Data at the root level is invalid. Line 1, position 1." for XML Document? LINQ TO XML