Solved

How to publish XML data

Posted on 2004-10-19
8
583 Views
Last Modified: 2013-11-19
I need help on the technogly necessary to publish HTML docs from a produt description in XML
owerview:
I am a c++ programmer creating applications to design our products
I am currently writing the product description into excel files.
the product decription includes test and numerical data (as much as 5000 parameters)
I can write this into an XML file that will not get larger tham about 5 meg.
I am current using VS.net on winnt 4
All my customers are also on the same platform and use IE6


Now what i want to do is:
publish this on our intranet.
View the data in multi formats.
one view for the Eng.
another for purchasing
another for manufacturing
another for sales ect......

My research points to using XSLT and DOM to parse and publish the XML (this is all new to me)
Am I going in the best direction??
from the above description can you give me a high level outline of the task involve in doing this.
also can you point me to where to find doucmentation/demos on the process.

Thanks




0
Comment
Question by:MCofer
  • 4
  • 3
8 Comments
 
LVL 26

Expert Comment

by:rdcpro
ID: 12352865
This is an ideal application for XSLT.  While you can use DOM methods to get the data, in my experience it's rather slow and cumbersome.  There are a lot of good XSLT tutorials out there:

http://www.w3schools.com/

Another excellent site with an in-depth tutorial:

http://xfront.com

I have a number of code snippets a few tutorials on specific aspects of XSLT (and other things) on my own site:

http://rdcpro.com

If the difference between each department's view is primarily filtering the data to show only those parts the department is in, you can set a parameter externally (before you transform) that identifies the "view" and then you only need one XSLT.  

If you can post an example of what the XML would look like, I can give you a couple of specific examples.

Regards,
Mike Sharp
0
 

Author Comment

by:MCofer
ID: 12354785
This is an extremly simple sample.
Most of the data is either part nums  which even though they llook like ints are declared as strings and dimenisonal data as doubles
there are many occurances of the same part only varying in location

I'll take a better look at the links tomorrow.
This is my first shot at creating XML so please make any suggestion as to format that may help with  the XSLT

Thanks

 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <Layout>
  <LayoutNum StrVal="123456" />
  <EnNum StrVal="None" />
- <Frame>
  <PinAng DblVal="33.000000" />
  <BkfcDim DblVal="3.955000" />
  </Frame>
- <Arm>
  <ArmNum StrVal="501644" />
  <ArmSize DblVal="8.500000" />
  </Arm>
- <Stds>
  <Revision StrVal="F" />
  <MinMeshClr DblVal="0.071000" />
  </Stds>
- <Insert>
  <Name StrVal="2000054" />
  <Num IntVal="2000054" />
  </Insert>
- <Insert>
  <Name StrVal="2000064" />
  <Num IntVal="2000064" />
  </Insert>
- <Insert>
  <Name StrVal="6500002" />
  <Num IntVal="6500002" />
  </Insert>
- <Insert>
  <Name StrVal="1091101" />
  <Num IntVal="1091101" />
  </Insert>
- <Insert>
  <Name StrVal="5000205" />
  <Num IntVal="5000205" />
  </Insert>
- <Insert>
  <Name StrVal="5016089" />
  <Num IntVal="5016089" />
  </Insert>
- <Insert>
  <Name StrVal="5000204" />
  <Num IntVal="5000204" />
  </Insert>
- <Cone>
  <OversizeAng DblVal="3.000000" />
  <GagePntX DblVal="2.435007" />
  <GagePntY DblVal="0.603501" />
  <GageAng DblVal="38.281744" />
  <C_Dia DblVal="3.340682" />
  <GageFlat DblVal="0.062000" />
  <SurfExp DblVal="0.031000" />
  </Cone>
- <Cone>
  <OversizeAng DblVal="3.000000" />
  <GagePntX DblVal="2.435007" />
  <GagePntY DblVal="0.603501" />
  <GageAng DblVal="38.281744" />
  <C_Dia DblVal="3.340682" />
  <GageFlat DblVal="0.062000" />
  <SurfExp DblVal="0.031000" />
  </Cone>
- <Cone>
  <OversizeAng DblVal="3.000000" />
  <GagePntX DblVal="2.435007" />
  <GagePntY DblVal="0.603501" />
  <GageAng DblVal="38.281744" />
  <C_Dia DblVal="3.340682" />
  <GageFlat DblVal="0.062000" />
  <SurfExp DblVal="0.031000" />
  </Cone>
  </Layout>
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 12355487
>This is my first shot at creating XML so please make any suggestion

it's hard to say something meaningfull regarding XML format, before you say us what the domain area you are working with, and what do you want to express with XML.
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 12361764
You should realize, too, that unless you specify and attach a schema, this XML won't have any real typing.  So programatically you may consider DblVal to be a double, but in the XML it's just a string unless specified otherwise.  If you're only using the XML for display, it probably doesn't matter.  However, if you're updating the XML through some interface (as opposed to generating it) or if you're using the XML in some sort of code or process, then you'll probably want to write a schema and explicitly define each type.

As far as rendering goes, if you use XSLT, judging from this example you're going to need to understand Meunchian grouping pretty well.  Then it's mostly a matter of how you want to display the data.  XSLT can work with pretty much any XML, so I wouldn't worry too much there.  It is, however, uncommon to see attributes named with the data type, as in StrVal and IntVal.  In this case:

<Insert>
  <Name StrVal="2000054" />
  <Num IntVal="2000054" />
</Insert>

It can be clear that <Name> is a string, and <Num> is a number.  Attribute centric XML is ok, as long as the values are guaranteed to be simple types (strings, numbers etc).  If an attribute might ever need children, then it's better to use an element.  

So in addition to the way you chose, there are several ways to represent the XML for the Insert:

<Insert Name="2000054" Num="2000054"/>
or
<Insert>
  <Name>2000054</Name>
  <Num>2000054</Num>
</Insert>

A case where the approach might matter is if you have an element like:

<Hole diameter="0.5"/>

If you later decide to add a tolerance to the dimension, it becomes a bit trickier.  You could simply add a tolerance attribute to the Element, but what if the original XML looked like:

<Hole diameter="0.5" depth="0.75"/>

You'd probably need a tolerance for *each* dimension.   An improvement would be:

<Hole>
  <diameter plusTolerance="0.005" minusTolerance="0.000">0.5</diameter>
  <depth plusTolerance="0.010" minusTolerance="0.010">0.75</depth>
</Hole>

Also, as far as naming conventions go, terseness is of minimal important.  In fact, this is even stated right in the requirements for the original XML specification.  Longer names can make it much easier to understand.  

In my experience, being consistent about using either attributes or elements can be easier to use with a database, but that may not matter to you--and shouldn't necessarily govern the design.  XML that is hierarchically organized can be easier to render.  When you go from a tabular format (like Excel) to a flat XML format, you lose some of the advantages of XML's hierarchical design.  For example:

<?xml version="1.0" encoding="UTF-8"?>
<Part>
      <Name>Foo Part</Name>
      <PartNumber>XRD-2741</PartNumber>
      <Assemblies>
            <Insert Name="2000054" Num="2000054"/>
            <Insert Name="2002345" Num="2002345"/>
            <Insert Name="1923454" Num="1923454"/>
            <Cone
                  OversizeAngl="3.000000"
                  GagePntX="2.435007"
                  GagePntYl="0.603501"
                  GageAng="38.281744"
                  C_Dial="3.340682"
                  GageFlat="0.062000"
                  SurfExp="0.031000" />
      </Assemblies>
      <Drawings CurrentRevision="F">
             <Standards>
                  <MinMeshClr>0.071000</MinMeshClr>
             </Standards>
      </Drawings>
</Part>

0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 26

Expert Comment

by:rdcpro
ID: 12361803
Drat...posted before I was finished...

Anyway, I wanted to finish with the statement that this example isn't necessarily the *best* way to create the XML (in particular, I wasn't consistent with how I specified <Inserts> and how I did <Standards>), but it's *one* way.  In short, as long as you don't violate the basic rules of well-formedness, you can do pretty much anything you want.  There are "best practices", but there are no hard rules (other than well-formedness!).

Regards,
Mike Sharp
0
 

Author Comment

by:MCofer
ID: 12364349
This is very helpfu!!!l I am just beginning tio digest it all. I'm going to leave this open for a few days and do some testing.
I'm sure i'll have a few more questions.

I am going to also need to parse the XML back into a C++ data class using (MSXML4)
I thought the data types SrtVal,DblVal as attributes would make it easy to do data conversions later.
The parser reads all values as strings correct???
But I will still need to read the data by name and would  at that time know the data type.

Looking at your example
This seems to be the best format using elements and adding attributes if necessary;
<Insert>
  <Name>2000054</Name>
  <Num>2000054</Num>
  <Daimeter>.504</Daimeter>
  <Length>.750</Length>
</Insert>
 <Cone>
               <OversizeAngl>3.000000 </OversizeAngl>
               <GagePntX>2.435007</GagePntX>
               <GagePntY>0.603501 </GagePntY>
               <GageAng>38.281744</GageAng>
               <C_Dia>3.340682</C_Dia>
               <GageFlat>0.062000</GageFlat>
               <SurfExp>0.031000</SurfExp>
</Cone>
<Cone>                                                                    //another Cone Diffrent Data
               <OversizeAngl>3.5000000 </OversizeAngl>
               <GagePntX>2.10000</GagePntX>
               <GagePntY>0.75000 </GagePntY>
               <GageAng>44.69999</GageAng>
               <C_Dia>3.340682</C_Dia>
               <GageFlat>0.062000</GageFlat>
               <SurfExp>0.031000</SurfExp>
</Cone>




Thanks
0
 
LVL 26

Accepted Solution

by:
rdcpro earned 500 total points
ID: 12364515
Well, like I said, there's no one "right" way.  No matter what you do, when you're done you'll understand the problem domain better, and wish you'd done it differently!  ;^)

As far as the datatyping goes, you should probably read about nodeTypedValue, which will give you the value of a node in it's defined data type.  So, if you write a W3C XML Schema, and define every node in the datatype you need, you don't really have to worry about parsing the name of an attribute and figuring out what type it is.  In fact, the Schema will not only type the data for you, it will let you know if for some reason the data gets wacky, and doesn't correctly evaluate to the correct type.

From an MSDN Example:

var xmlDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var xmlDocTest = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var strDestination;
var childNode;
xmlDoc.documentElement = xmlDoc.createElement("Test");
childNode = xmlDoc.createNode(3, "", "");
xmlDoc.documentElement.appendChild(childNode);
xmlDoc.documentElement.dataType = "bin.hex";
childNode.nodeTypedValue = "ffab123d";
xmlDocTest.async = false;
xmlDocTest.load(xmlDoc);
if (xmlDoc.parseError.errorCode <> 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   alert(xmlDocTest.xml);
}


Result (in a message box)
<Test xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.hex">ffab123d</Test>


The C++ syntax is:
HRESULT get_nodeTypedValue(
    VARIANT *typedValue);
HRESULT put_nodeTypedValue(
    VARIANT typedValue);

Parameters
    typedValue [out, retval][in]
            Value of this node in its defined data type, if such a data type is defined. If this node has no content,
            the value of the typedValue parameter is Null.

C/C++ Return Values
    S_OK
            Value returned if successful.
    E_INVALIDARG
            Value returned if the typedValue parameter is Null.
    E_FAIL (for put_nodeTypedValue only)
            Value returned if an error occurs.


And the datatype mappings (first value is the variant returned and the second is the data type of the corresponding element):

VT_BSTR string
VT_BSTR number
VT_I4 Int
VT_CY Fixed.14.4  
VT_BOOL Boolean
VT_DATE dateTime
VT_DATE dateTime.tz
VT_DATE Date
VT_DATE Time
VT_DATE Time.tz
VT_I1 i1 byte
VT_I2 i2
VT_I4 i4, int
VT_UI1 ui1
VT_UI2 ui2
VT_UI4 ui4
VT_FLOAT r4
VT_DOUBLE r8, float
VT_BSTR uuid
VT_ARRAY bin.hex
VT_ARRAY bin.base64


One more thing to be aware of; if you use attributes, you won't be able to specify the datatype in a dt:dt attribute, you can only specify it in a schema.  But if you use Elements, you can do this (assuming <Root> is the root element of the XML, or at least an ancestor of <GageAng>):

<Root xmlns:dt="urn:schemas-microsoft-com:datatypes">
    [...] boatloads of XML here[...]
    <GageAng dt:dt="float">44.69999</GageAng>
    [...] boatloads of XML here[...]
</Root>

dt:dt could be a float or "r8" here--they're the same thing:

<Root xmlns:dt="urn:schemas-microsoft-com:datatypes">
    [...] boatloads of XML here[...]
    <GageAng dt:dt="r8">44.69999</GageAng>
    [...] boatloads of XML here[...]
</Root>

This will allow you to use nodeTypedValue when you later use this data, and it will be coerced into the correct data type.

Finally, make sure when you do all this, you use MSXML 4, not 3.  MSXML 3 came out before the W3C Schema was finalized.

Regards,
Mike Sharp
0
 

Author Comment

by:MCofer
ID: 12404135
This was a great help.
I'm sure I'll have more specific questions but this has got me started
Thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now