|
A little more context would help.
Are you familiar with XML? Have you worked with XML before?
|
|
|
|
|
Hi All,
I have an simple xml file for which I generated an xsd file using Altova XMLSpy tool.
As I wanted the end user who makes the xml entry to enter an unique ID which is an attribute of one of the elements. I modified the generated xsd file to accomodate this rule by including "xs:unique" node and entered valid values(i believe)but to no avail.
Below is my xml file.
<?xml version="1.0"?>
<wwdfdb:DDB xmlns:wwdfdb="http://www.xybec.com/ns/wwdfdb" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xybec.com/ns/wwdfdb Sample.xsd">
<wwdfdb:MyList>
<wwdfdb:Num id="3020">
<wwdfdb:Ver>1.0.0.1</wwdfdb:Ver>
<wwdfdb:Status>InUse</wwdfdb:Status>
</wwdfdb:Num>
<wwdfdb:Num id="3021">
<wwdfdb:Ver>1.0.0.1</wwdfdb:Ver>
<wwdfdb:Status>InUse</wwdfdb:Status>
</wwdfdb:Num>
</wwdfdb:MyList>
</wwdfdb:DDB>
Below is the xsd file for the xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2009 sp1 (http:
<xs:schema xmlns="http://www.xybec.com/ns/wwdfdb" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.xybec.com/ns/wwdfdb">
<xs:element name="Ver">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="1.0.0.1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Status">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="InUse"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Num">
<xs:complexType>
<xs:sequence>
<xs:element ref="Ver"/>
<xs:element ref="Status"/>
</xs:sequence>
<xs:attribute name="id" use="required">
<xs:simpleType>
<xs:restriction base="xs:short">
<!--<xs:enumeration value="3020"/>
<xs:enumeration value="3021"/>-->
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="MyList">
<xs:complexType>
<xs:sequence>
<xs:element ref="Num" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<!--added below lines to achieve uniqueness for attribute 'id' but to no avail-->
<xs:unique name="MyUniqueID">
<xs:selector xpath="Num"/>
<xs:field xpath="@id"/>
</xs:unique>
</xs:element>
<xs:element name="DDB">
<xs:complexType>
<xs:sequence>
<xs:element ref="MyList"/>
</xs:sequence>
<xs:attribute name="version" use="required">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:enumeration value="1.0"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
Plese note that I have included the 'xs:unique' element in the xsd file above to enforce the rule above but to no avail.
Could somebody correct me and guide such that I can enforce an rule in xsd such that any new block added in the xml file should have an unqiue id.
|
|
|
|
|
In xmllint (libxml2's standalone app), I needed to add an explicit namespace specification for the elements in the unique spec:
<xs:unique name="MyUniqueID" xmlns:wwdfdb="http://www.xybec.com/ns/wwdfdb" >
<xs:selector xpath="wwdfdb:Num"/>
<xs:field xpath="@id"/>
</xs:unique>
That did the right thing (validating uniqueness, rejecting sameness) in the limited testing I did!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
It works.
Thanks a lot Stuart for the solution.
|
|
|
|
|
Hello, i have a semi-weird xml file to parse with xsl. The xml has an extra tag which defines what the data is below , how do i go about disregarding anything with ColName in my xsl ?
XML
<br />
<?xml version="1.0" encoding="ISO-8859-1"?><br />
<br />
<Report><br />
<br />
<ColName> DateTime </ColName><br />
<ColName> PointName </ColName><br />
<ColName> PointValue </ColName><br />
<br />
<Record><br />
<Date> data </Date><br />
<Name> data </Name><br />
<Value> data </Value><br />
</Record><br />
<br />
<Report><br />
<br />
<ColName> DateTime </ColName><br />
<ColName> PointName </ColName><br />
<ColName> PointValue </ColName><br />
<br />
<Record><br />
<Date> data </Date><br />
<Name> data </Name><br />
<Value> data </Value><br />
</Record><br />
<br />
<Record><br />
<Date> data </Date><br />
<Name> data </Name><br />
<Value> data </Value><br />
</Record><br />
<br />
<br />
<br />
</Report><br />
<br />
<code><br />
<br />
<br />
XSL<br />
<br />
<code><?xml version="1.0"?><br />
<xsl:stylesheet version = "1.0"<br />
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"><br />
<xsl:output method="text"/><br />
<xsl:strip-space elements = "Report"/><br />
<xsl:template match="Record"><br />
<text>
</text><br />
<xsl:text/><xsl:value-of select="normalize-space(Record)"/><xsl:text/><br />
<xsl:value-of select="normalize-space(DateTime)"/>,<xsl:text/><br />
<xsl:value-of select="normalize-space(PointName)"/>,<xsl:text/><br />
<xsl:value-of select="normalize-space(PointValue)"/>,<xsl:text/><br />
<text>
</text><br />
<xsl:text disable-output-escaping = "yes" ><br />
</xsl:text><br />
</xsl:template><br />
</xsl:stylesheet>
Thanks
Matt
|
|
|
|
|
matty2desmara wrote: how do i go about disregarding anything with ColName in my xsl ?
I suspect you're running foul of the default behaviour of XSL, which passes through all tags unchanged unless you say otherwise. Add a root element template that just processes what you want, like I've put in here?
<?xml version="1.0"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements = "Report"/>
<big> <xsl:template match="/">
<xsl:apply-templates select="//Record"/>
</xsl:template></big>
<xsl:template match="Record">
<text>
</text>
<xsl:text/><xsl:value-of select="normalize-space(Record)"/><xsl:text/>
<xsl:value-of select="normalize-space(DateTime)"/>,<xsl:text/>
<xsl:value-of select="normalize-space(PointName)"/>,<xsl:text/>
<xsl:value-of select="normalize-space(PointValue)"/>,<xsl:text/>
<text>
</text>
<xsl:text disable-output-escaping = "yes" >
</xsl:text>
</xsl:template>
</xsl:stylesheet>
I'm presuming the use of DateTime, PointTime and PointValue in your XSL is a typo?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi all,
I will be involved in a project where I must translate multiple EDI formats into XML and vice versa? Rather than code all this which I suspect will be impossible as I will be constantly hit with new formats, I was thinking that my app should load an XSLT map with the rules for the translation. I can then create custom XSLT maps on demand. Now my questions before I start:
1. Looking on the web, it seems all articles on XSLT are now quite old so I am wondering if this technology has been superseded in .NET? If so, by what?
2. If I should use XSLT, what would be the best tools to create the maps? I think hand coding will be tough/a bore. By looking the on the web, it seems Stylus Studio is possibly the way to go?
I'm not really ridged in my thoughts here so happy if I need to go off in another direction.
Many thanks for any advice.
|
|
|
|
|
As long as the EDI is an XML format or can be read into an XMl DOM using a custom XML reader, I'd say it's a splendid idea. Declarative programming - lovely!
tig2810 wrote: Looking on the web, it seems all articles on XSLT are now quite old so I am wondering if this technology has been superseded in .NET? If so, by what?
Don't think so.
tig2810 wrote: If I should use XSLT, what would be the best tools to create the maps? I think hand coding will be tough/a bore. By looking the on the web, it seems Stylus Studio is possibly the way to go?
Stylus Studio certainly seems to have strong EDI and XSLT support (looking at their website). Looks good!
I've always hand-coded my XSLT, but I've tended to do more involved stuff than mapping data formats, which has required some slightly out of the ordinary XSLT - it's been closer to functional programming thatn data mapping .
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks very much for the reply. Good to see I am headed in the right direction!
|
|
|
|
|
Hi Experts,
Has anyone tried getting Infopath generated XML file to work on the web and vice versa?
Someone mention using XForms and I am trying to learn how to work with that.
Also, how can this be implemented using php?
Thanks in advance.
|
|
|
|
|
I'll do a refresher on Infopath. It was interconnected with something uniquely Microsoft, which was why I had to reject it. Can't remember more off-hand.
I did a project in XForms. It works, but only in certain browsers. I used a FF add-in, which worked fine. I also tried XSmiles...less stable, but may be better now.
It's worth the effort to understand XForms!!! It's GORGEOUS in it's simplicity. Data and presentation are separate. You're able to do more with XForms than you ever could with XHTML & HTML (multiple submssions and types of submissions, locally or on a server and so on).
Here's a header code sample from my project. You'll see the submission types and the differences I talked about:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"<br />
xmlns:xmml="http://www.myDataModel/xmml"><br />
<head><br />
<title>Shopping List</title><br />
<xf:model id="default" ><br />
<xf:instance><br />
<xmml:data><br />
<xmml:storeName></xmml:storeName><br />
<xmml:productChoice></xmml:productChoice> <br />
</xmml:data><br />
</xf:instance><br />
<xf:submission id="clientList" action="ClientList.xml" <br />
method="put" /><br />
<xf:submission id="tempList" action="file:///c:/tmp/ClientList.xml" <br />
method="put" replace="none"/><br />
<xf:submission id="reloadList" action="file:///c:/tmp/ClientList.xml" <br />
method="get" replace="instance"/><br />
</xf:model>
I've not tried XForms with php and my use is server context only. I only know that php wraps around HTML. HTML is wrapped around XForms.
XForms is still wild west territory. You'll learn as you go. It's worth it though. w3schools.com and their xforms tutorial is a good place to start. I ended up learning more advanced things from xsmiles and w3.org.
|
|
|
|
|
Did a look up on Infopath. The reasons I didn't use it for a class project was due to it's proprietary software. To nutshell Infopath too much, it's just another XML web service and can run async like Ajax.
My thoughts are that it's always better to learn the guts, like XForms and XML web services (using REST & SOAP) before bumping up to proprietary software, like Infopath.
Most likely, Infopath runs async by creating a data model like the XForms example above and submitting it to a service. I'd have to dig much deeper and it wouldn't probably answer your question enough.
Gotta love the details! :LOL:
|
|
|
|
|
For XForms use with every recent browser, have a look at XSLTForms : http://www.agencexml.com/xsltforms
|
|
|
|
|
Hi all!
I am a new one in XML. Now I have a project which need to call GetObject() function with the syntax of JavaScript. The aim of this action is to get an object of a COM. The COM is created by myself. This COM has several interface. One of these interface is named as NetworkClass. And the COM is named as WindowsNetwork.
Now I'm sure that this COM had been registed in windows correctly. I write the code as following:
var WindowsNetwork = GetObject("WindowsNetwork,NetworkClass");
But an error is return. It say that this object is undefined. The variable is invalid. I think this is because of the syntax error of GetObject(). Maybe it shouldn't be written as this if a COM have several interface. So I hope someone could be kind to tell me how to write this code. Thx!
Best Regards!
whiteclouds
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
Try with
var WindowsNetwork = GetObject("WindowsNetwork.NetworkClass");
Also Refer
http://www.c-point.com/javascript_tutorial/jsfncGetObject.htm
Regards
Akhila
|
|
|
|
|
Thx for your reply. My problem had been resolved.
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
Hi,
I have the xml document like,
<?xml version="1.0" encoding="utf-8"?>
<Drive>
<folders>
<folder name="f1">
</folder>
<folder name="f2">
</folder>
</folders>
</Drive>
Please notice that there is no xmlns used and I cannot used xmlns in this xml document.
I have problem creating schema (.xsd) file to validate this xml document.
My schema is like
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.tempuri.com/temp"
elementFormDefault="qualified">
<element name="Drive">
<complexType>
<sequence>
<element ref="folders" minOccurs="0" maxOccurs="1"/>
</sequence>
</complexType>
</element>
<element name ="folders">
<complexType>
<sequence minOccurs ="0" maxOccurs ="unbounded">
<element ref ="folder"/>
</sequence>
</complexType>
</element>
<element name ="folder">
<complexType>
<sequence>
<element ref ="folders" minOccurs ="0" maxOccurs="1" />
</sequence>
<attribute name ="name" type="string" />
</complexType>
</element>
</schema>
But the ref attribute is not working. ie the attribute 'folders' cannot reference the element 'folders'. I am using VS2008 to create/edit xsd file. VS2008 shows warning message
"The 'http://www.w3.org/2001/XMLSchema:folders' element is not declared.". The same exception occurs if I run my c# program to valid the xml.
Could you please suggest me how to refernce element using ref attribute without using namespace? Is there any other workaround?
Thanks.
Prakash
|
|
|
|
|
I may have steered you wrong before saying that ref didn't work without namespaces. I think they do, but there are a few things that need to change before your schema could possibly work:
- Remove the targetNamespace attribute - this is the namespace that the elements your defining in the schema (Drive, folder
- You need to change the default namespace declaration to be a named namespace:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
and prefix all elements that come from the XML Schema namespace with the namespace prefix you choose (xs in this case)
Oh and one other thing - learn about XML namespaces, what they imply and how they interact with XML Schemas. You need to know this stuff if you're going to design XML Schemas - you need to know it if you're working with XML!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
You have referenced the element 'folders' before it was described in your xml that is why you are getting this error. Try changing the order in your xml .
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.tempuri.com/temp"
elementFormDefault="qualified">
&lt;element name ="folders"&gt;
&lt;complexType&gt;
&lt;sequence minOccurs ="0" maxOccurs ="unbounded"&gt;
&lt;element ref ="folder"/&gt;
&lt;/sequence&gt;
&lt;/complexType&gt;
&lt;/element&gt;
<element name="Drive">
<complexType>
<sequence>
<element ref="folders" minOccurs="0" maxOccurs="1"/>
</sequence>
</complexType>
</element>
<element name ="folder">
<complexType>
<sequence>
<element ref ="folders" minOccurs ="0" maxOccurs="1" />
</sequence>
<attribute name ="name" type="string" />
</complexType>
</element>
</schema>
Regards
Akhila
|
|
|
|
|
The job I'm working on wants to use XML for storing strings in the various languages we plan to support.
We're choosing xml for a variety of reasons:
Not tied to a specific platform (.resx etc)
Doesn't require application recompilation on editing/adding strings
Doesn't require recompilation on adding new languages.
Human readability.
Overall, I agree with using XML, but my boss has tasked me with finding out the reasons why *not* to use it. To play the Devil's Advocate so to speak.
While I can think up a few reasons, I'm coming short on anything really convincing, which I'm worried is due to my bias of actually wanting to use it.
Anyone have some solid reasons not to use XML for this type of data storage?
I have:
Possible slower load time at initial startup, or at string access.
Possible memory overhead depending on schema, and how we handle language data loading.
Resource size: xml contains a lot of overhead in the markup language (this is a concern for us)
|
|
|
|
|
You've probably hit most of the reasons you might not want to use XML. Couple of other reasons to use XML - a) not having to write your own parsing code and b) XML files explicitly define the encoding they use.
This design decision doesn't seem to be so important that you want to take too much effort over it. Using XML's a no-brainer, really, IMO.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi All,
I used an Altova XMLSpy tool generate an XSD file for my XML file.
The xsd equivalent for an simple xml element "Mfg" generated via the tool was
<xs:element name="Mfg">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
I found out that modifying the above xsd to the one below just works fine.
<xs:element name="Mfg" type="xs:string"/>
Just wanted to know if these 2 XSD representations for the xml element are the same or are they different.
Do the elements xs:simpleType, xs:restriction above have any signifance int he above mentioned scenario?
(Actually tried going through MSDN but conldn't infer much info).
It would be of great help if somebody points out the differences between the 2 if any and brief on it's significance.
|
|
|
|
|
They are exactly the same because the restriction specified doesn't actually restrict the base type (i.e. xs:string). Here's an example of a restriction on a string using a regular expression pattern that could be used as a variable or type name:
<xs:simpleType>
<xs:restriction baseType="xs:string">
<xs:pattern value="[A-Za-z][A-Za-z0-9_]*"/>
</xs:restriction>
</xs:simpleType>
[edit]I recommend downloading the Essential XML Quick Reference PDF[^], as it's a very easy to use reference to XML technologies, including XSD.[/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Oh. I see.
Thanks for the info.
|
|
|
|
|
<Root>
<Products>
<Item ItemColor="Red" ItemName="Item1"/>
<Item ItemColor="White" ItemName="Item2"/>
<Item ItemColor="Blue" ItemName="Item2"/>
</Products>
<Desciptions>
<Color ColorName="Red" ColorId="15"/>
<Color ColorName="White" ColorId="14"/>
<Color ColorName="Blue" ColorId="13"/>
</Desciptions>
</Root>
<xsl:template match="/">
<xsl:for-each select="Products/Item">
<tr>
<td><xsl:value-of select="ItemColor" /></td>
<td> ? Right here I want the ColorId of the
ColorName that matches ItemColor found by the previous select ?</td>
</tr>
</xsl:for-each>
</xsl:template match="/">
Thank You for reading this post.
modified on Friday, July 10, 2009 6:12 PM
|
|
|
|