xdocument

Xdocument does not print declaration

I try to use the domainpeople.com API and to do I need to use XML. Currently I have an error saying "apiProtocol is not found" I guess then that my Xml document is malformed. The Current xml sent is : <apiProtocol version="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNameSpaceSchemaLocation="checkrequest.xsd"> <ch...

How to use XmlDocument and/or XDocument to parse numeric character references encoded in Windows 1252?

I'm working with XML data from an application where we get XML like this: <elt attrib="Swedish: &#228; &#246; Euro: &#128; Quotes: &#145; &#146; &#147; &#148;"> Swedish: &#228; &#246; Euro: &#128; Quotes: &#145; &#146; &#147; &#148; </elt> I want the attribute value and inner text values to be Swedish: ä ö Euro: € Quotes: ‘ ’ “ ” b...

ASP.Net MVC XDocument Html.Decode/Encode Help

Can someone explain the best way to handle this approach. I am using TinyMCE editor. The information typed into this is loaded into a XDocument and then written to the database as a string by doing XDocument.ToString() When I output the content to a webpage I load the string from the database into a XDocument, find the element and do a...

How do I add multiple Namespace declarations to an XDocument?

I'm using an XDocument to build an Xml document in a known structure. The structure I am trying to build is as follows: <request xmlns:ns4="http://www.example.com/a" xmlns:ns3="http://www.example.com/b" xmlns:ns2="http://www.example.com/c" > <requestId>d78d4056-a831-4c7d-a357-d14402f623fc</requestId> .... </request> Notice th...

Update XElement value in XDocument?

I have a XDocument with XElements such as this: <PageContent> <Text>My Text</Text> <Image>image.jpg</Image> </PageContent> I want to find the Text element and update its value. I have some LINQ working but its returning the value rather than allowing me to update the XElement and XDocument in return. ...

Problem with XDocument (C#)

what is wrong with this code XDocument xDocument = new XDocument(); for (int i = 0; i < 5; i++) { xDocument.Element("PlayerCodes").Add( new XElement("PlayerCode", i.ToString()) ); } xDocument.Save(@"c:\test.xml"); I am getting error " Object reference not set to an instance of an object." Basically I want to create the xml fil...

XDocument/Linq concatenate attribute values as comma separated list.

If I have the following xml: XDocument xDocument = new XDocument( new XElement("RootElement", new XElement("ChildElement", new XAttribute("Attribute1", "Hello"), new XAttribute("Attribute2", "World") ), new XElement("ChildElement"...

How do I add a document type to an XDocument?

I have an existing XDocument object that I would like to add an XML doctype to. For example: XDocument doc = XDocument.Parse("<a>test</a>"); I can create an XDocumentType using: XDocumentType doctype = new XDocumentType("a", "-//TEST//", "test.dtd", ""); But how do I apply that to the existing XDocument? ...

Add HTML 5 doctype to XDocument (.NET)

When creating a doctype for an System.Xml.Linq.XDocument like this: doc.AddFirst(new XDocumentType("html", null, null, null)); The resulting saved XML file starts with: <!DOCTYPE html > Notice the extra space before the closing angle bracket. How can I prevent this space appearing? I'd like a clean way if possible :) ...

Can I assign a BaseUri to an XDocument?

When I load an XML document from disk into an XDocument, that XDocument has a ready-only property BaseUri that contains the original XML document's location on disk. In other words, XDocument doc = XDocument.Load(@"c:\temp\doc.xml"); Console.Out.WriteLine(doc.BaseUri); // Outputs "file:///c:/temp/doc.xml" If I create a new XDocument...

XDocument or XMLDocument

Hi everyone, I am now learning XMLDocument but I've just ran into XDocument and when I try to search the difference or benefits of them I can't find something useful, could you please tell me why you would use one over another ? Thanks in advance. ...

How to keep in session XML-based objects?

I'm receiving data from web-services in XML and I'm using that data via objects, build upon received XML. So, sometimes I need to store such user-specific objects between requests in session. I know that XMLDocument couldn't be stored explicitly (state server)... so I'm making a terrible construction like: private string _data; public X...

Returning Element value deep inside XDocument

I have the following XML and I have been trying Descendents().Descendents().Descendents to retrieve an element value but I can't get it to work. I want to return the first value found in the first element of PersonID. It is a string so I am doing this: XDocument XDoc = XDocument.Parse(XmlString); <Root> <Code>200001</Code> <MsgTy...

Embedding an XDocument within XAML

How can I embed an XDocument within XAML? I've got the following but Visual Studio won't let me put any XML in the XDocument: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:xlinq="clr-namespace:System.Xml.Linq;assembly=System.Xml.Linq" ...

How to query an XDocument with LINQ when elements have a colon in their name?

I am trying to use LINQ to XML in an with the XDocument object. How do you query the result element in the example below? <serv:header> <serv:response> <serv:result>SUCCESS</serv:result> <serv:gsbStatus>PRIMARY</serv:gsbStatus> </serv:response> </serv:header> When I use a statement like this, I get the exception 'Ad...

Remove all empty elements using xlinq

I'm doing some transforms using xlinq and some of those transforms can result in leaving empty elements in the document. Once I am done all of those transforms, how can I query an xdocument for all empty elements? In other words; if I remove all <a> tags which happen to be the only element inside an <li> tag, how do I remove the empty...

Processing XML from a Table (with one line in one record each)

IBM only provides a database connection to the iSeries, thus I have to work around this issue with using a table to pass data from the iSeries to .NET. The RPGLE program creates an XML document in a table for processing on the .NET side. The thing is that on one record in the table has one line of the XML document. To help visualize pr...

how to load a XDocument when the xml is in a string variable?

How do I load an XDocument when the xml is in a string variable? ...

Efficent way of retrieveing HttpWebResponse and putting it in XDocument

There is a local service from which I need to consume a generated XML Document Stream. Though the end point is not a REST service per se. I wanted to be sure the method I've outlined below is the most efficient way of getting the response returned into an XDocument. Uri requestUri = null; Uri.TryCreate(String.Format(SearchAddress, filte...

Preserving whitespaces and line-breaks in XML Document

I have an xml document like this, <Customer ID = "000A551" Name = "Robert" Salaried = "yes" Area = "VA" /> Please note the how attributes are line-breaked and white-spaced for the editing and reading convenience. When using XDocument or XmlDocument to modify this document whole formatting goes...