xml

Get the Node value from XML

How do I use XPathNavigator.Evaluate ( or other methods in XPathNavigator) to obtain the ISBN value for the following xml input? <?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 Prejud...

De/Serialize directly To/From XML Linq

Is there any way to de/serialize an object without round-tripping a XmlDocument/temp string? I am looking for something like the following: class Program { static void Main(string[] args) { XDocument doc = new XDocument(); MyClass c = new MyClass(); c.SomeValue = "bar"; doc.Add(c); Conso...

How to suppress XML tag for list property

Is it possible to avoid list property tags when serializing? //[Serializable()] - removed, unnecessary public class Foo { protected List<FooBar> fooBars = new List<FooBar>(); public virtual List<FooBar> FooBars { get { return fooBars; } set { fooBars = value; } } } // [Serializable()] - removed, unnecessary public class FooBar ...

How to get the raw xml returned from a webservice request?

Does anyone know of a simple way of getting the raw xml that is returned from querying a webservice? I have seen a way of doing this via Web Services Enhancements, but I don't want an added dependency. ...

Transforming flat file to XML using XSLT-like technology

I'm designing a system which is receiving data from a number of partners in the form of CSV files. The files may differ in the number and ordering of columns. For the most part, I will want to choose a subset of the columns, maybe reorder them, and hand them off to a parser. I would obviously prefer to be able to transform the incoming d...

Is there a more elegant way to convert an XML Document to a String in Java than this code?

Here is the code currently used. public String getStringFromDoc(org.w3c.dom.Document doc) { try { DOMSource domSource = new DOMSource(doc); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.ne...

XML Parsing

Hi All i want add the new node as parent node of the old nodes in XML using C#.for example node have the following XMl file <bookstore> <books> <author> </author> </books> </bookstore> like that now i want add the new like below <bookstore> <newnode> <books> <author> </author> </books> </newnod...

Adjusting XML config files from a script

I'm working on automating the configuration of several JBoss servers, which involves editing a substantial number of XML files. I'd like to script all these changes as much as possible. But the "standard" tools (sed, grep et al) do not work well with XML. Without necessarily resorting to a higher-level language, how can I script e.g. th...

What is the best way to build up an XML document in .NET?

There seem to be many options to create an XML document in .NET. What's the best approach? ...

Copying Xml comments for implemented intefaces

When you use a tool like Resharper to implement an interface, you can choose to copy the Xml documentation markup. Of course there are times when the comments are going to be different for the concrete classes - but in the cases where they are identical, we now have a clear violation of don't repeat yourself. Is this an unavoidable viola...

Generating SQL using XML and XSLT

I have an XML definition that contains an element with child elements. For example: <a> <b> <c>C</c> <d>D</d> </b> </a> I have an XSLT with an output of text. For example: <xsl...> <xsl:output method="text" indent="yes"/> <xsl:template match="/"> <xsl:copy-of select="/a/b" /> ... I want to copy the entire b element ...

Extract a Byte[] from an XElement with Linq to Xml

Hi, I am saving some small images to Xml as a Byte[] via the following XElement construct.. XElement xe = new XElement("Images", from c in qry select new XElement("Image", new XAttribute("Date", c.Date), new XElement("Data", c.Bytes))); the Bytes property is a Byte[], looking at the resulting elem...

ASP.NET - controls generated by xslt transformation

hi! i'm generating controls dynamically on my asp.net page by xslt transformation from an xml file. i will need to reference these controls from code behind later. i would like to add these references to the list/hashtable/whatever during creation (in xslt file i suppose) so that i could reach them later and i have no idea how to do this...

Attribute/element co-occurrence constraint in XML Schema

Is it possible to create an XML Schema which imposes a co-occurrence constraint to an attribute/element pair? <primitive-list> <primitive name="P1"> <definition><!-- primitive specification --></definition> </primitive> <primitive name="P2"> <definition><!-- primitive specification --></definition> </primitive>...

Java GUI described in XML

My company currently evaluates the development of a Java FAT client. It should support a dynamic GUI and has as much logic as possible on the server side. Hence the idea came up to send the screen as XML to the FAT client, show it to the user and send the entered data similar to "html form" back in a structure like: <fields> <field ty...

How do I include a DTD in an XML file that will be loaded using getResourceAsStream()?

I have an xml file ('videofaq.xml') that defines a DTD using the following DOCTYPE <!DOCTYPE video-faq SYSTEM "videofaq.dtd"> I am loading the file from the classpath (from a JAR actually) at Servlet initialization time using: getClass().getResourceAsStream("videofaq.xml") The XML is found correctly, but for the DTD in the same pac...

Found unexpected <Submission> inside <<<<ROOT>>>>. This is not a valid child element

I am trying to validate xml file against schema using XML::Validator::Schema. But it gives me this error: Found unexpected <Submission> inside <<<<ROOT>>>>. This is not a valid child element. [Ln: 2, Col:119] Note: <Submission> is the very first element I have after <xml version="1.0" encoding="UTF-8"?> I can't figure out what it ...

Restrict exclusive key-value pairs in XSD

In the XSD, there are two elements, A and B. They are siblings. A can have a value of either "1" or "2". B can have a value of either "one" or "two". I want to restrict this, however, so that only "1-one" and "2-two" are valid combinations, not "1-two" or "2-one". Is there a way of doing that in the XSD? ...

Comparing XML in a unit test in Python

I have an object that can build itself from an XML string, and write itself out to an XML string. I'd like to write a unit test to test round tripping through XML, but I'm having trouble comparing the two XML versions. Whitespace and attribute order seem to be the issues. Any suggestions for how to do this? This is in Python, and I'm usi...

How can you identify mutliple elements with the same name in XPath?

What if I had a document that had multiple elements with the same name -- how would I retrieve, for instance, the second element? <doc> ... <element name="same">foo</element> ... <element name="same">bar</element> ... <element name="same">baz</element> ... </doc> I'd expect something like //elem[@name='same'][2] to work. Additiona...