Search Results

Search found 314 results on 13 pages for 'xmldocument'.

Page 1/13 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • xmldocument and nested schemas

    - by Stuart
    Using c# and .net 3.5 I'm trying to validate an xml document against a schema that has includes. The schemas and there includes are as below Schema1.xsd - include another.xsd another.xsd - include base.xsd When i try to add the Schema1.xsd to the XmlDocument i get the following error. Type 'YesNoType' is not declared or is not a simple type. I believe i'm getting this error because the base.xsd file is not being included when i load the Schema1.xsd schema. I'm trying to use the XmlSchemaSet class and I'm setting the XmlResolver uri to the location of the schemas. NOTE : All schemas live under the same directory E:\Dev\Main\XmlSchemas Here is the code string schemaPath = "E:\\Dev\\Main\\XmlSchemas"; XmlDocument xmlDocSchema = new XmlDocument(); XmlSchemaSet s = new XmlSchemaSet(); XmlUrlResolver resolver = new XmlUrlResolver(); Uri baseUri = new Uri(schemaPath); resolver.ResolveUri(null, schemaPath); s.XmlResolver = resolver; s.Add(null, XmlReader.Create(new System.IO.StreamReader(schemaPath + "\\Schema1.xsd"), new XmlReaderSettings { ValidationType = ValidationType.Schema, XmlResolver = resolver }, new Uri(schemaPath).ToString())); xmlDocSchema.Schemas.Add(s); ValidationEventHandler valEventHandler = new ValidationEventHandler (ValidateNinoDobEvent); try { xmlDocSchema.LoadXml(xml); xmlDocSchema.Validate(valEventHandler); } catch (XmlSchemaValidationException xmlValidationError) { // need to interogate the Validation Exception, for possible further // processing. string message = xmlValidationError.Message; return false; } Can anyone point me in the right direction regarding validating an xmldocument against a schema with nested includes.

    Read the article

  • XmlDocument.InnerXml is null, but InnerText is not

    - by Adam Neal
    I'm using XmlDocument and XmlElement to build a simple (but large) XML document that looks something like: <Widgets> <Widget> <Stuff>foo</Stuff> <MoreStuff>bar</MoreStuff>...lots more child nodes </Widget> <Widget>...lots more Widget nodes </Widgets> My problem is that when I'm done building the XML, the XmlDocument.InnerXml is null, but the InnerText still shows all the text of all the child nodes. Has anyone ever seen a problem like this before? What kind of input data would cause these symptoms? I expected the XmlDocument to just throw an exception if it was given bad data. Note: I'm pretty sure this is related to the input data as I can only reproduce it against certain data sets. I also tried escaping the data with SecurityElement.Escape but it made no difference.

    Read the article

  • Avoid XmlDocument validating namespaces in C#

    - by Abbey Kingston
    Hello, I'm trying to find a way of indenting a HTML file, I've been using XMLDocument and just using a XmlTextWriter. However I am unable to format it correctly for HTML documents because it checks the doctype and tries to download it. Is there a "dumb" indenting mechanism that doesnt validate or check the document and does a best effort indentation? The files are 4-10Mb in size and they are autogenerated, we have to handle it internal - its fine, the user can wait, I just want to avoid forking to a new process etc. Essentially, right now I use a MemoryStream, XmlTextWriter and XmlDocument, once indented I read it back from the MemoryStream and return it as a string. Failures happen for XHTML documents and some HTML 4 documents because its trying to grab the dtds. I tried setting XmlResolver as null but to no avail :(

    Read the article

  • XmlDocument from LINQ to XML query

    - by Ben
    I am loading an XML document into an XDocument object, doing a query and then returning the data through a web service as an XmlDocument object. The code below works fine, but it just seems a bit smelly. Is there a cleaner way to take the results of the query and convert back to an XDocument or XmlDocument? XDocument xd = XDocument.Load(Server.MapPath(accountsXml)); var accounts = from x in xd.Descendants("AccountsData") where userAccounts.Contains(x.Element("ACCOUNT_REFERENCE").Value) select x; XDocument xd2 = new XDocument( new XDeclaration("1.0", "UTF-8", "yes"), new XElement("Accounts") ); foreach (var account in accounts) xd2.Element("Accounts").Add(account); return xd2.ToXmlDocument();

    Read the article

  • XmlDocument caching memory usage

    - by mdsharpe
    We are seeing very high memory usage in .NET web applications which use XmlDocument. A small (~5MB) XML document is loaded into an XmlDocument object and stored in HttpContext.Cache for easy querying and XSLT transformation on each page load. The XML is modified on disk periodically so a cache has a dependency on the file. Such an application appears to be using hundreds of megabytes of RAM. I have experimented with requesting garbage collection on each request start, and this keeps the RAM usage far lower but I cannot imagine this is good practise. Does anyone have any suggestions as to how we can achieve the same goal but with lower RAM usage?

    Read the article

  • Is there a way to make XmlDocument parsing less strict

    - by Istrebitel
    I am making a program that will store its data in an XML file. When people write XML they can make subtle mistakes, like ending a comment with - so it looks like <!-- comment ---> or adding a </>inside an attribute. Naturally, the XML still can be read all right, but trying to input this text into XmlDocument will give a syntax error (and it wont be parsed). Is there a way to make XmlDocument less strict and make it ignore violations of the standard that do not make the document unparseable? For example, its clear that <!-- comment ---> is still a comment even though it contains - at the end which is against the standard specification).

    Read the article

  • Search for nodes by name in XmlDocument

    - by RajenK
    I'm trying to find a node by name in an XmlDocument with the following code: private XmlNode FindNode(XmlNodeList list, string nodeName) { if (list.Count > 0) { foreach (XmlNode node in list) { if (node.Name.Equals(nodeName)) return node; if (node.HasChildNodes) FindNode(node.ChildNodes, nodeName); } } return null; } I call the function with: FindNode(xmlDocument.ChildNodes, "somestring"); For some reason it always returns null and I'm not really sure why. Can someone help me out with this?

    Read the article

  • XmlDocument SelectNodes(Xpath): Order of result

    - by crauscher
    This is an example xml from MSDN <?xml version="1.0"?> <!-- A fragment of a book store inventory database --> <bookstore xmlns:bk="urn:samples"> <book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8"> <title>Pride And Prejudice</title> </book> <book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1"> <title>The Handmaid's Tale</title> </book> <book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6"> <title>Emma</title> </book> <book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3"> <title>Sense and Sensibility</title> </book> </bookstore> When I select all book nodes using the following code, which order will these nodes have? XmlDocument doc = new XmlDocument(); doc.Load("booksort.xml"); var nodeList =doc.SelectNodes("bookstore/book"); Will the order of the items in the nodelist be the same as the order in the xml? Is this order guaranteed?

    Read the article

  • C# XML export for Excel table using XmlDocument

    - by Mark
    I am trying to write the following into an XML document: <head> <xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> other code here </x:ExcelWorksheet> </x:ExcelWorksheets> </x:ExcelWorkbook> </xml> </head> However, if I use the following code, it strips out the 'x:'. System.Xml.XmlDocument document = new System.Xml.XmlDocument(); System.Xml.XmlElement htmlNode = document.CreateElement("html"); htmlNode.SetAttribute("xmlns:o", "urn:schemas-microsoft-com:office:office"); htmlNode.SetAttribute("xmlns:x", "urn:schemas-microsoft-com:office:excel"); htmlNode.SetAttribute("xmlns", "http://www.w3.org/TR/REC-html40"); document.AppendChild(htmlNode); System.Xml.XmlElement headNode = document.CreateElement("head"); htmlNode.AppendChild(headNode); headNode.AppendChild( document.CreateElement("xml")).AppendChild( document.CreateElement("x:ExcelWorkbook"))).AppendChild( document.CreateElement("x:ExcelWorksheets")).AppendChild( document.CreateElement("x:ExcelWorksheet")).InnerText="other code here"; How can I stop this from happening? Thanks!

    Read the article

  • XmlDocument filter nodes by datetime string

    - by Eatdoku
    Trying to apply filter / attribute comparison in the Xmldocument. Obviously , the following code snippet wouldn't work because the expression can't be converted using number() function. (according to the answer of my other question). I'm wondering if there is a way to do the DateTime string comparison in XmlDoc. XmlNodeList test = x2PathDoc.SelectNodes("//Config /Entity [@TargetDateTime> '2010-12-19T03:25:00-08:00']");

    Read the article

  • How to remove all comment tags from XmlDocument

    - by Filburt
    How would i go about to remove all comment tags from a XmlDocument instance? Is there a better way than retrieving a XmlNodeList and iterate over those? XmlNodeList list = xmlDoc.SelectNodes("//comment()"); foreach(XmlNode node in list) { node.ParentNode.RemoveChild(node); }

    Read the article

  • Convert XMLDocument to String

    - by mnh
    Here is how I'm currently converting XMLDocument to String StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter); xmlDoc.WriteTo(xmlTextWriter); return stringWriter.ToString(); The problem with this method is that if I have " ((quotes) which I have in attributes) it escapes them. For Instance: <Campaign name="ABC"> </Campaign> Above is the expected XML. But it returns <Campaign name=\"ABC\"> </Campaign> I can do String.Replace "\" but is that method okay? Are there any side-effects? Will it work fine if the XML itself contains a "\"

    Read the article

  • How to add xmlnamespace to a xmldocument

    - by CruelIO
    Hi Im trying to create a xml the should look like this <?xml version="1.0" encoding="iso-8859-1"?> <MyTestSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Tests> <Test> <messaure>1</messaure> <height>4</height> </Test> <Test> <messaure>4</messaure> <height>53</height> </Test> </Tests> </MyTestSet> Its not a problem to create the Tests or Test elements, but what is the best way to Create the "MyTestSet" including the namespaces? Im using c# XMLDocument

    Read the article

  • How to modify exiting XML file with XmlDocument and XmlNode in C#

    - by Nano HE
    I already implemented to create the XML file below with XmlTextWriter when application initialization. And know I don't know how to update the childNode id value with XmlDocument & XmlNode. Is there some property to update the id value? I tried InnerText but failed. thank you. <?xml version="1.0" encoding="UTF-8"?> <Equipment xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <License licenseId="" licensePath=""/> <DataCollections> <GroupAIDs> <AID id="100"> <Variable id="200"/> <Variable id="201"/> </RPTID> <AID id=""> <ReportVariable id="205"/> </AID> <AID id="102"/> </GroupAIDs> <GroupBIDs> <BID id="2000"> <AID id="100"/> </BID> <BID id="2001"> <AID id="101"/> <AID id="102"/> </BID> </GroupBIDs> <GroupCIDs> <BID id="8"/> <BID id="9"/> <BID id="10"/> </GroupCIDs> </DataCollections> </Equipment>

    Read the article

  • C# XmlDocument.CreateDocumentType

    - by Thorbjørn Reimann-Andersen
    hi all, I am trying to figure out of the CreateDocumentType() works in C# and although i have already found and read the msdn page on it, i can not get it to work for me. I am simply trying to create this line in my xml document: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Can someone help me out with the syntax required for this

    Read the article

  • Relative XPath node selection with C# XmlDocument

    - by lox
    Imagine the following XML document: <root> <person_data> <person> <name>John</name> <age>35</age> </person> <person> <name>Jim</name> <age>50</age> </person> </person_data> <locations> <location> <name>John</name> <country>USA</country> </location> <location> <name>Jim</name> <country>Japan</country> </location> </locations> </root> I then select the person node for Jim: XmlNode personNode = doc.SelectSingleNode("//person[name = 'Jim']"); And now from this node with a single XPath select I would like to retrieve Jim's location node. Something like: XmlNode locationNode = personNode.SelectSingleNode("//location[name = {reference to personNode}/name]"); Since I am selecting based on the personNode it would be handy if I could reference it in the select. Is this possible?.. is the connection there? Sure I could put in a few extra lines of code and put the name into a variable and use this in the XPath string but that is not what I am asking.

    Read the article

  • What are the advantages to use StringBuilder versus XmlDocument or related to create XML documetns?

    - by Rob
    This might be a bit of a code smell, but I have seen it is some production code, namely the use of StringBuilder as opposed to XmlDocument when creating XML documents. In some cases these are write once operations (e.g. create the document and save it to disk) where as others are passing the built string to an XmlDocument to preform an XslTransform to a document that is returned to the client. So obvious question: is there merit to doing things this way, is it something that should be done on a case-by-case basis, or is this the wrong way of doing things?

    Read the article

  • How to Deserialize XMLDocument to object in C#?

    - by Deepfreezed
    I have a .Net webserivce that accepts XML in string format. XML String sent into the webserivce can represent any Object in the system. I need to check the first node to figure out what object to deserialize the XML string. For this I will have to load the XML into an XMLDocument (Don't want to use RegEx or string compare). I am wondering if there is a way to Deserialize the XMLDocument/XMLNode rather that deserializing the string to save some performance? Is there going to be any performance benefit serializing the XMLNode rather that the string? Method to Load XMLDocument public void LoadFromString(String s) { m_XmlDoc = new XmlDocument(); m_XmlDoc.LoadXml(s); } Thanks

    Read the article

  • Converting XDocument to XmlDocument and vice versa.

    - by Workshop Alex
    It's a very simple problem that I have. I use XDocument to generate an XML file. I then want to return it as a XmlDocument class. And I have an XmlDocument variable which I need to convert back to XDocument to append more nodes. So, what is the most efficient method to convert XML between XDocument and XmlDocument? (Without using any temporary storage in a file.)

    Read the article

  • XmlDocument.WriteTo truncates resultant file

    - by Brad Heller
    Trying to serialize an XmlDocument to file. The XmlDocument is rather large; however, in the debugger I can see that the InnerXml property has all of the XML blob in it -- it's not truncated there. Here's the code that writes my XmlDocument object to file: // Write that string to a file. var fileStream = new FileStream("AdditionalData.xml", FileMode.OpenOrCreate, FileAccess.Write); xmlDocument.WriteTo(new XmlTextWriter(fileStream, Encoding.UTF8) {Formatting = Formatting.Indented}); fileStream.Close(); The file that's produced here only writes out to line like 5,760 -- it's actually truncated in the middle of a tag! Anyone have any ideas why this would truncate here?

    Read the article

  • XmlDocument.Load() throws XmlSchemaValidationException

    - by Praetorian
    Hi, I'm trying to validate an XML document against a schema (which is embedded in my program as a resource). I got everything to work, so I tried to test for errors by adding a second sibling node in the XML at a location where the schema specifies maxOccurs="1". The problem is that my ValidationEventHandler is never getting called, also XmlDocument.Load() is throwing an XmlSchemaValidationException exception when I'd expected XmlDocument.Validate() to do that. This is the code I have: private void ValidateUserData( string xmlPath ) { var resInfo = Application.GetResourceStream( new Uri( @"MySchema.xsd", UriKind.Relative ) ); var schema = XmlSchema.Read( resInfo.Stream, SchemaValidationCallBack ); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add( schema ); schemaSet.ValidationEventHandler += SchemaValidationCallBack; XmlReaderSettings settings = new XmlReaderSettings(); settings.Schemas = schemaSet; settings.ValidationType = ValidationType.Schema; XmlDocument doc = new XmlDocument(); using( XmlReader reader = XmlReader.Create( xmlPath, settings ) ) { doc.Load( reader ); // <-- This line throws an exception if XML is ill-formed reader.Close(); } doc.Validate( SchemaValidationCallBack );// <-- This is never reached } private void SchemaValidationCallBack( object sender, ValidationEventArgs e ) { Console.WriteLine( "SchemaValidationCallBack: " + e.Message ); } How do I get the callback to be called so I can handle validation errors? Thanks for your help!

    Read the article

  • Query an XmlDocument without getting a 'Namespace prefix is not defined' problem

    - by Dan Revell
    I've got an Xml document that both defines and references some namespaces. I load it into an XmlDocument object and to the best of my knowledge I create a XmlNamespaceManager object with which to query Xpath against. Problem is I'm getting XPath exceptions that the namespace "my" is not defined. How do I get the namespace manager to see that the namespaces I am referencing are already defined. Or rather how do I get the namespace definitions from the document to the namespace manager. Furthermore tt strikes me as strange that you have to provide a namespace manager to the document which you create from the documents nametable in the first place. Even if you need to hardcode manual namespaces why can't you add them directly to the document. Why do you always have to pass this namespace manager with every single query? What can't XmlDocument just know? The Code: XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(programFiles + @"Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\HfscBookingWorkflow\template.xml"); XmlNamespaceManager ns = new XmlNamespaceManager(xmlDoc.NameTable); XmlNode referenceNode = xmlDoc.SelectSingleNode("/my:myFields/my:ReferenceNumber", ns); referenceNode.InnerXml = this.bookingData.ReferenceNumber; XmlNode titleNode = xmlDoc.SelectSingleNode("/my:myFields/my:Title", ns); titleNode.InnerXml = this.bookingData.FamilyName; ... The Xml: <?xml version="1.0" encoding="UTF-8" ?> <?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:Inspection:-myXSD-2010-01-15T18-21-55" solutionVersion="1.0.0.104" productVersion="12.0.0" PIVersion="1.0.0.0" ?> <?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?> - <my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-01-15T18:21:55" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"> <my:DateRequested xsi:nil="true" /> <my:DateVisited xsi:nil="true" /> <my:ReferenceNumber /> <my:FireCall>false</my:FireCall> ...

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >