XPathDocument to xmldocument

How to create XPathDocument object from xmldocument object
thanks
0
anonymous (74722)
3/17/2005 6:31:10 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
1016 Views

Similar Articles

[PageSpeed] 49

vikram wrote:
> How to create XPathDocument object from xmldocument object

First, be aware that such converting means copying the whole set of data 
in the XML document.
Second, it's easy:
XPathDocument doc = new XPathDocument(new XmlNodeReader(xmlDoc));

-- 
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
0
Oleg
3/17/2005 9:57:44 AM
Reply:

Similar Artilces:

XmlDocument with URL
My goal is to load an xml document from a remote url, make some changes to it, and then display it in a webpage. Say my codebehind looks like this private void Page_Load(Object sender, EventArgs e) { XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8); XmlDocument doc = new XmlDocument(); doc.Load(http://somexmlgeneratedhere.com?id=333); //manipulate the doc here doc.WriteTo(writer); } Im not getting the full document from the URL, I'm sure Im doing this wrong. Can anyone point me in the right direction? thanks in advance Dave He...

Internal problem on XmlDocument.Load( )
I have this really frustrating problem when calling XmlDocument.Load(string filename). Whenever I call this method in a web application in my Windows XP development PC, I get the following error: Specified argument was out of the range of valid values. Parameter name: The specified value must be greater than 0. Here's the stack trace: ------------------------- [ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: The specified value must be greater than 0.] System.Net.ServicePoint.set_ConnectionLimit(Int32 value) +60 System.Xml.XmlDo...

XSLT transform XmlDocument to XmlDocument?
I just want to make a transformation on the fly, without having to save the XML document to a file before or after the transformation. I don't find any examples of this. I see that the XslTranform.Transform() method can return an XmlReader, but how can that reader be converted to an XmlDocument object? Big thanks, Gustaf Gustaf Liljegren wrote: > I just want to make a transformation on the fly, without having to save > the XML document to a file before or after the transformation. I don't > find any examples of this. See <http://groups-beta.google.com/group/mic...

Loading XmlDocument with a file on network?
Can you load an XmlDocument with a file located on a network share? I thought maybe the XmlResolver could be used XmlUrlResolver resolver = new XmlUrlResolver() resolver.Credentials = CredentialCache.DefaultCredentials // Create and load the XmlDocument XmlDocument doc = new XmlDocument() doc.XmlResolver = resolver; // Set the resolver doc.Load(@"\\devsrv\profiles\0004.xml") OR.. doc.Load("//devsrv/profiles/0004.xml") But I get: "Logon failure: unknown user name or bad password" The problem is probably that the account that your application is running under...

XPathDocument to xmldocument
How to create XPathDocument object from xmldocument object thanks vikram wrote: > How to create XPathDocument object from xmldocument object First, be aware that such converting means copying the whole set of data in the XML document. Second, it's easy: XPathDocument doc = new XPathDocument(new XmlNodeReader(xmlDoc)); -- Oleg Tkachenko [XML MVP, MCP] http://blog.tkachenko.com ...

XmlDocument --> XPathDocument
Hi All, I'd like to convert from an XmlDocument to an XPathDocument (without saving the XmlDocument down to a file - this is a web app). I can't see any way to do this. Any help is appreciated. --Ed XmlDocument doc = ... XPathDocument xpathDoc = new XPathDocument(new XmlNodeReader(doc)); "Ed S" <user@example.net> wrote in message news:OC$9G3XVEHA.3428@TK2MSFTNGP12.phx.gbl... > Hi All, > > I'd like to convert from an XmlDocument to an XPathDocument (without > saving the XmlDocument down to a file - this is a web app). I can't see > any way...

Problem using XPathDocument
Hi, I am getting XmlException while running the following code: string sConfigXPath = Constants.CONST_CONFIG_XPATH + "[@"+Constants.CONST_CONFIG_TYPE_ID + "="+this.iType + "]"; string sConfigFile = Constants.CONST_CONFIG_FILE_LOCATION; //Returns me the physical path @"C:\Temp\MyXml.xml" XPathDocument xpdConfig = new XPathDocument(sConfigFile,XmlSpace.Default); //XmlException raised here. XPathNavigator xpnConfig = ((IXPathNavigable)xpdConfig).CreateNavigator(); XPathNodeIterator iter = xpnConfig.Select(sConfigXPath); while(iter.MoveNext(...

Opening and altering XML-doc using XmlDocument wrecks havoc on doc
Hi I am trying to post-process some XML-documents from some third-party software. I open them, find the right element, manipulate the text and write it back to the element. Dim x As New Xml.XmlDocument Dim nl As Xml.XmlNodeList Dim text As String Dim textOutput As String x.Load(filename) nl = x.GetElementsByTagName("text") [snip, some manipulation of the text, not important...] nl.Item(0).InnerText = "<![CDATA[ " & textOutput & " ]]>" 'nl.Item(0).InnerText = textOutput x.Save("C:\Temp\XmlYt.xml") Now, the data I write ...

XmlDocument
Hi Oleg and All, Is this correct? Can I do this? <code> XmlDocument doc=new XmlDocument(); XPathNavigator nav = doc.CreateNavigator(); //Load the xml file. Change path if needed doc.Load(@"..\..\..\books.xml"); XslTransform xslt = new XslTransform(); xslt.Load(@"D:\XML\XSL Ex2\Personnel2.xsl"); StringWriter fs = new StringWriter(); xslt.Transform(doc, null, fs, null); XmlNode node=doc.SelectSingleNode("bookstore"); <- Here is the problem </code> I need to transform the XML First using xslt.transform then tak...

Clone XPathDocument
Hello everyone, I am converting a small personal program to .NET 2.0 and changing from using XmlDocument to XPathDocument. Ok so my problem is that the system currently clones a XmlDocument (it gets edited / used / and tossed but the orginal document is needed later). Is there some way to "Clone" an XPathDocument? And if so how? Thanks, blair XPathDocument is read-only. What is the reason to clone it? "blair" <blair@discussions.microsoft.com> wrote in message news:0D49D95E-0962-4FD2-A35D-C74187D9850B@microsoft.com... > Hello everyone, > I am converting a sm...

trying to instantiate XPathDocument with MemoryStream
Hi, I am trying to instantiate an instance of XPathDocument after serializing XML into a memory stream. Here is my method that uses XmlSerializer public MemoryStream SerializeXMLSelectedApplication() { System.IO.MemoryStream stream = new MemoryStream(); try { XmlSerializer serializer = new XmlSerializer(typeof(Subject)); serializer.Serialize(stream, this); } catch(SystemException ex) { Console.WriteLine(ex.Message); } return stream; } //Using the return stream, I attempt to instantiate XPathDocument XPathDocument doc = new XPathDoc...

Strange question: Add same nodes to XmlDocument
Hi all, i'm trying to add same node to XmlDocument. This is Xml that I want to create: <TableColumns> <TableColumn><Width>1.5in</Width></TableColumn> <TableColumn><Width>1.5in</Width></TableColumn> <TableColumn><Width>1.5in</Width></TableColumn> <TableColumn><Width>1.5in</Width></TableColumn> </TableColumns> I tried to do this with XmlDocument method AppenChild but it remove duplicate node. If it is possibile I dont want to use XmlTextWriter. Any idea? Thx Marco I begin loading x...

Inherit from XmlDocument?
I have a class that contains a certain kind of XML document. The input file is *not* an XmlDocument, but when loaded, I want it to work like the XmlDocument class, like: MyDocument doc = new MyDocument(); doc.Load("input.txt"); // doc is now an XmlDocument // Query or modify the XmlDocument as usual doc.Save("output.xml"); // doc saved using XmlDocument.Save(); That is, the input file is not XML, and the Load() method is obviously not the same, but otherwise the MyDocument class is a copy of XmlDocument. Can someone please show me what the MyDocument class shall l...

XPathDocument Threading Question
I have a web application where I am trying to cache and XPathDocument the XPathDocument is created as follows. XPathDocument xdoc = new XPathDocument(new StringReader(ruleXml)); Then I want to just cache this xdoc and retrieve it for each request. And then call XPathNavigator nav = xdoc.CreateNavigator(); on each thread. My question is whether this is thread safe or not. Can you have multiple XPathNavigator classes on different threads with the same underlying XPathDocument? If not I will just cache the ruleXml string and create a new XPathDocument on each thread. Just wondering what ...

xmldocument vs. xpathdocument
Hi, Could someone explain the functional difference between these classes? From what I understand, xpathdocument is faster in some scenarios, but I'm not sure why. Further, why is it that the method of getting xml data into these two classes differs? (xmldocument uses the load method, whereas xpathdocument doesn't have this available and one must specify the path to the xml data in the constructor, or so it seems). Any help would be appreciated. Thanks... -Ben Ben R. wrote: > Could someone explain the functional difference between these classes? From > what I underst...

XmlDocument.LoadXml and namespaces
Hi; Once I have loaded an xml file into a DOM, is there any way to then get any namespace declarations that were in the xml file? Or are those just discarded as the DOM is populated? And if you can't get it from the DOM, any other way to get the namespace(s)? I'm assuming doing a SAX read which returns each element including NameSpaces and pull it form that (and build up the DOM at the same time)? In my case I get a Stream so I can't read it twice as the Stream may not support reset. And it may have NS elements - but I don't know if there are any or what they are excep...

From n xmlReader to single XPathDocument?
My problem is this. I have to create several xmlReader objects each retrieving 'for xml' formatted sql server data. I then need to peice them together into a single document and place them into a single XPathDocument which is then transformed throughout the web site with different XslTransformations. I realize that the Xpathdocument will accept a XmlReader as an object but I have 5 of them so how to 'best' combine. The resulting XpathDocument is placed into the Cache and is only updated twice a day. Cheers Keith Note: I do note have access to the SQLXML objects on the prod...

Placing dataset into XPathDocument
I have a merged dataset that contains xml read from SQL Server. I need to place the data into an XPathDocument. I can do the following: mydataset.writeXML("mydata.xml") dim xpdoc as new XPathDocument("mydata.xml") Problem is it seem rather redundent to write data currently in memory to disk in order to be read on the next line. According to the documentation the writeXML method supports writing to System.IO.Stream and the XPathDocument supports load from System.IO.Stream but I can not seem to get this to work. Any suggestions? Cheers Keith Keith Chadwick wrote: &...

Problem with XmlDocument
This is a multi-part message in MIME format. ------=_NextPart_000_0014_01C63C5C.BDB2FE80 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Before that nothing I want to ask for excuses for my english level. The problem that I have is the following one: I have a file xml with "encoding=3DISO-8859-1" and accents. When in VB.NET, in a Form I write: Dim objxml as new XmlDocument and then when de Forms load: objxml.Load("C\....") The debugger gives me the following error: "A first chance exception of type 'Sy...

XmlDocument vs XPathDocument performance
Hi... I've been trying to improve the performance of our xml handling, so I've been doing some timing tests lately and ran across something I thought odd - XPathDocument seems slightly slower than XmlDocument. I've run the tests several times and have tried to eliminate extraneous variables like disk access but every time, XPathDocument comes up slower by a few percent. I'd expected it to be faster since it's a read-only representation. Am I doing something wrong? start = Timers.QueryPerformanceCounter(); for (int idx = 0; idx < 50000; idx++) { StringReader...

XPathDocument faster than XMLDocument ?
working with a local xml file. perform an xpath query and iterate through the resultset to build a virtual DataTable -- each DataRow composed of multiple attributes of each element in the xpath resultset ... is working with an XPathDocument faster than working with an XMLDocument ? if so , how much faster ? John A Grandy wrote: > is working with an XPathDocument faster than working with an XMLDocument ? > if so , how much faster ? Sure. XPathDocument is in average 30-40% faster and takes less memory. Always use it unless you need to edit XML in memory (I'm talking about ..NE...

Canonicalized XML from XmlDocument?
How can I obtain the C14N canonicalized format of an XML document subtree? Any help is greatly appreciated. I'm using the XmlDsigC14NTransform object to obtain the C14N canonicalized format. The output looks right, but I can't guarantee it... some xmlns attributes have been removed. An input document that I am validating indicates that it uses this transformation. Still, when I send the output of the transformation to the SHA1 hashing algorithm, ComputeHash yields a different DigestValue than the one on the input document. The input document is created using simple code for SignedX...

How to ignore namespace in XMLDocument
Hi, I have this XML file that I need to parse. <property> <name>some name</name> <value>some value</value> </property> <report xmlns="http://schemas.site.com/test/test/"> <reportElementList> <reportElement> .... .... </reportElement> </reportElementList> My application works fine when I use doc.SelectNodes for 'property'. However, for 'report' it fails because of the xmlns=.... Is there a way to instruct the XMLDocument to ignore namespaces? BTW, I hav...

XmlDocument Trouble
Hi, I don't know why, but I can't seem to get this to work: Public Sub DoSomething() Dim sb as New StringBuilder() sb.Append("http://webservices.amazon.com/onca/xml?") sb.Append("Service=AWSECommerceService&SubscriptionId") sb.Append("=0525E2PQ81DD7ZTWTK82&Operation=ItemSearch") sb.Append("&SearchIndex=Books&Keywords=css") sb.Append("&ResponseGroup=ItemAttributes,Offers") Dim tr as New XmlTextReader(sb.ToString()) tr.Read() Dim xDoc as XmlDocument = New XmlDocument() xDoc.Load(tr) tr.Close() ...

XPathDocument and hex 0x1A
I am trying to extract specific fields out of XML documents using XPathDocument & Xpath. The basic code outline is as follows: try { ...//Load file as XpathDocument .. XPathDocument xp = new XPathDocument(filename, System.Xml.XmlSpace.None); //Select the required nodes.. .... } catch(Exception e) { errlog.WriteLine("\nERROR :{0}", e.Message); errlog.WriteLine("ERROR TARGETSITE: {0}", e.TargetSite); errlog.WriteLine("ERROR SOURCE: {0}", e.Source); } While processing some of those files, I get an error. The error (from the catch stat...