Using JAXB to extract inner text of XML element

You can use the @XmlAnyElement annotation as described by bmargulies. To map to the object model in your question you can leverage a DOMHandler. Main import javax.xml.bind.annotation.*; @XmlRootElement(name=”main”) @XmlAccessorType(XmlAccessType.FIELD) public class Main { private String name; private Integer maxInstances; @XmlAnyElement(value=ParameterHandler.class) private String parameters; } ParameterHandler import java.io.*; import javax.xml.bind.ValidationEventHandler; import javax.xml.bind.annotation.DomHandler; import javax.xml.transform.Source; import javax.xml.transform.stream.*; … Read more

Do you always have to have a root node with xml/xsd?

from the XML specification at http://www.w3.org/TR/REC-xml/ (fifth edition) chapter 2 This says “Each XML document has both a logical and a physical structure. Physically, the document is composed of units called entities. An entity may refer to other entities to cause their inclusion in the document. A document begins in a “root” or document entity.” … Read more

XML tagname starting with number is not working

An XML element whose name starts with a number is illegal XML. You should not start with numbers. XML elements must follow these naming rules: Names can contain letters, numbers, and other characters Names cannot start with a number or punctuation character Names cannot start with the letters xml (or XML, or Xml, etc) Names … Read more

Is it possible to apply normalize-space to all nodes XPath expression finds?

Using XPath “/html/body/table/tr/td/text()” we will get [” Item 1″, ” Item 2″]. Is it possible to trim white space for example using normalize-space() function to get [“Item 1”, “Item 2”]? Not in XPath 1.0. In Xpath 2.0 this is simple: /html/body/table/tr/td/text()/normalize-space(.) In XPath 2.0 a location step of an XPath expression may be a function … Read more

Parsing local XML file using Sax in Android

To read from XML in your app, create a folder in your res folder inside your project called “xml” (lower case). Store your xml in this newly created folder. To load the XML from your resources, XmlResourceParser myxml = mContext.getResources().getXml(R.xml.MyXml);//MyXml.xml is name of our xml in newly created xml folder, mContext is the current context … Read more

How do I use Powershell to add/remove references to a csproj?

I think the problem is that your XML file has a default namespace xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″. This causes problems with XPath. So you XPath //ProjectReference will return 0 nodes. There are two ways to solve this: Use a namespace manager. Use namespace agnostic XPath. Here’s is how you could use a namespace manager: $nsmgr = New-Object System.Xml.XmlNamespaceManager … Read more

Encoding XML element name beginning with a number?

The official word is that the restriction imposed on Xml naming conventions are inherited from Xml’s parent-set SGML, with one exception only: In Xml, as an additional option, names may begin with an underscore ‘_’ character. SGML was developed by IBM in the 1960s, by a group of minds that were thinking ‘1960s style’. As … Read more