I'm using the following code to update the root namespace
rootTreeNode.setAttributeNS("http://www.w3.org/2000/xmlns/" ,"xmlns:m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
dataServices.setAttribute("m:DataServiceVersion", "2.0");
Im trying to create new XML file with java and in the XML which I try
to create with dom code its look as follows:
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
when I open the file in visual studio i got error under the
m:DataServiceVersion
edmx:DataServices m:DataServiceVersion="2.0"
The error is:
the "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata:DataServiceVersion" attribute is not declared .
what am I doing wrong here ?
That looks like Visual Studio is trying to validate the XML file against a schema that doesn't allow the m:DataServiceVersion attribute on that particular element. You can't fix this without changing the schema but you might be able to suppress it by telling VS not to try and validate, but I'm not sure how you would go about doing that.
Related
I have an XML file and want to read the information using XPath, I want to read the 'listings_Id' and 'budget_remaining' together.
XML example
<ads>
<ad>
<listing_ids>
<listing_id>2235</listing_id>
<listing_id>303</listing_id>
<listing_id>394</listing_id>
</listing_ids>
<reference_id>11</reference_id>
<net_ppe>0.55</net_ppe>
<budget_remaining>50000.0</budget_remaining>
</ad>
<ad>
<listing_ids>
<listing_id>2896</listing_id>
</listing_ids>
<reference_id>8</reference_id>
<net_ppe>1.5</net_ppe>
<budget_remaining>1.3933399</budget_remaining>
</ad>
</ads>
I want to output it to a CSV file as the following
ListingId,BudgetRemaining
2235,0.55
303,0.55
394,0.5
2896,1.5
I am trying to use the example as
DataReader reader = new XmlReader(new File("links.xml"))
.addField("ListingId", "//ad/listing_ids/listing_id")
.addField("BudgetRemaining", "//ad/budget_remaining")
.addRecordBreak("//ad")
.setExpandDuplicateFields(true);
But it seems so I cannot find the jar file for XMLReader and DataReader and also I am going definitely wrong with the format. New to Java, please any help is appreciated.
You're following a tutorial for a commercial library ("Data Pipeline"), which is not shipped with the JDK and needs to be installed separately. Get if from the Download page and install it using their Getting Started manual.
Now, the classes should be found.
I am trying to auto generate a UPS label using XML.
I am generating a response in java that is coming back as
http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=1Z9422410395881216
But yet i am setting the link to be
http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=1Z9422410395881216
How do i stop it from showing up at & and instead having it show up as just the & symbol?
If you can't change the way you read your XML data then maybe try using unescapeXml method from StringEscapeUtils class from apache commons
String address = "http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=1Z9422410395881216";
System.out.println(StringEscapeUtils.unescapeXml(address));
result
http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=1Z9422410395881216
What you see is correct XML output, & should be specified as & for it to be proper XML. You shouldn't change it, or else any XML parser should fail on it.
The xml file is :
<xml-fragment xmlns:xyz="http://someurl">
<xyz:xyzcontent>
<contentattribute>
<key>tags</key>
<value>tag1, tag2</value>
</contentattribute>
</xyz:xyzcontent>
...
I've tried the following:
XPathExpression createdDateExpression = xpath.compile("/contentattribute/key/attribute::tags/value");
There are several problems with your query.
The XML is broken (root tag not closed) -- probably just a copy/paste mistake
You're starting somewhere right in the middle of the XML tree, but actually try to query from the root node. Use the descendant-or-self-axis // in the beginning.
Which attribute are you querying using the attribute-axis? There is none.
Where did you register the namespaces? What namespace is xyz, anyway? I guess it's actually vp, but you obfuscated incompletely (or are not giving all relevant parts of the document).
Use predicates and string comparison to filter at axis steps.
Try following:
Make sure to register the namespace, have a look at the reference for that (or give more information).
Use the XPath query //contentattribute[key='tags']/value
I added to my application a nice XML source viewer. Now, I have an XSD scheme that defines the xml document. Any idea where to start on adding some source validation that relies on this scheme?
Thanks!
To check that your XML is well-formed, just run it through a DocumentBuilderFactory parser. To additionally validate it against an .xsd schema referenced in the XML, call:
factory.setValidating( true );
If the xsd schema is not referenced within the XML that you are validating, you can supply it yourself like this:
factory.setAttribute(JAXP_SCHEMA_SOURCE, new File(schemaSource) );
For more information, read the article from Oracle here:
http://download.oracle.com/javaee/1.4/tutorial/doc/JAXPDOM8.html
This is the first time I've ever tried to use JAXB for anything at all and I'm running into a problem.
I'm trying to use JAXB's XJC tool to convert an XSD file into Java class files when I get this error:
parsing a schema...
[ERROR] The prefix "msdata" for attribute "msdata:ColumnName" associated with an element type "xs:simpleContent" is not bound.
line 10 of file:/home/jeremy/TypeDefs.xsd
Failed to parse a schema.
Line 10 in the schema file reads:
<xs:simpleContent msdata:ColumnName="paramText" msdata:Ordinal="1">
and you can see the whole thing here.
edit: It turns out the XSD file was missing the namespace declaration for msdata. Simply adding xmlns:msdata="http://schemas.microsoft.com/2003/07/msdata.xsd" fixed the problem.
You need to have the msdata namespace prefix mapped. Like
<xs:schema targetNamespace="http://maps.trimet.org/maps/model/xml"
xmlns="http://maps.trimet.org/maps/model/xml"
....
xmlns:msdata="http://yournamespace.com/foo">