Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all 935 articles
Browse latest View live

How to map XML to graph/visualize the TREE OF LIFE?

$
0
0

Hi all

If this is the wrong place to post please let me know :)

THE GOAL

To build a 3D tree of life visualization (see photo below) in Unity for a education project that is real-time intractable like at https://itol.embl.de/itol.cgi (for eg if you mouse over a line it triggers the line changes color, triggers pop-up information from the nodes, etc). 

THE CHALLENGE / OPPORTUNITY?

Understand this is basic for ppl who get data structures and C# and I'm happy to keep pushing. However after a few days, I'm still struggling to converting the XML data into something usable in Unity.

THE QUESTIONS

1) what's the best way to convert phyloXML data into objects I can vizualize as a 3D TREE OF LIFE?

2) Am I the right track (see below)? If no, what am I missing? What mistakes am I making? And what else do I need to consider to make this real-time interactible tree of life? 

WHAT I'VE DONE THUS FAR

From my research, most trees of life are represented in a phyloXML data format (such as https://itol.embl.de/itol.cgi) and happily, I found this phyloXML file which I've been using to form the tree: http://www.wellcometreeoflife.org/resources/tree-of-life-files/?sort=filetype&order=asc#xml

But how to convert this data into a 3d tree that surrounds a user?
My understanding (please correct if there's a better way), is I need to:
1) have some code that parses through the entire XML file and deserializes it into new data objects I can use to build a graph in Unity 
2) use some more code in Unity to instantiate Node and Link objects (from the classes generated in 1) to produce the 3d tree 

Re 1 – I came across this tutorial http://collaboradev.com/2014/03/12/visualizing-3d-network-topologies-using-unity/which was helpful in teaching me that I probably need the StreamReader and XMLDocument classes. However, its data uses a different schema (Graph ML) and after hours of playing around as a c# noob, I've been unable to map it to my tree.xml (phyloXML) data. 
See github of my adaptation of Jason's tutorial and attempt on github here: https://github.com/maxmagna2k/treelife/tree/master/ToL.01

Code (doesn't fn) here but the key parts aimed at mapping XML to node (or in pholoXML speak a 'clade' is lines 55-71):

using UnityEngine;
using System.Collections;
using System.Xml;
using System.IO;
using UnityEngine.UI;
namespace Topology
{
   public class GraphController : MonoBehaviour
   {
       public Node nodePrefab;
       public Link linkPrefab;
       private Hashtable nodes;
       private Hashtable links;
       private Text statusText;
       private int nodeCount = 0;
       private int linkCount = 0;
       private Text nodeCountText;
       private Text linkCountText;
       //Method for loading the GraphML layout file
       private IEnumerator LoadLayout()
       {
           string sourceFile = Application.dataPath + "/Data/tree-added-phylo-xml-schema.xml";
           statusText.text = "Loading file: " + sourceFile;
           //determine which platform to load for
           string xml = null;
           StreamReader sr = new StreamReader(sourceFile);
           xml = sr.ReadToEnd();
           sr.Close();
           XmlDocument xmlDoc = new XmlDocument();
           xmlDoc.LoadXml(xml);
           statusText.text = "Loading Topology";
           int scale = 1;
           XmlElement root = xmlDoc.FirstChild as XmlElement;
           for (int i = 0; i < root.ChildNodes.Count; i++)
           {
               XmlElement xmlGraph = root.ChildNodes[i] as XmlElement;
               for (int j = 0; j < xmlGraph.ChildNodes.Count; j++)
               {
                   XmlElement xmlNode = xmlGraph.ChildNodes[j] as XmlElement;
                   //create nodes
                   if (xmlNode.Name == "clade")
                   {
                       //float x = float.Parse(xmlNode.Attributes["x"].Value) / scale;
                       float y = float.Parse(xmlNode.Attributes["age_mya"].Value) / scale;
                       //float z = float.Parse(xmlNode.Attributes["z"].Value) / scale;
                       Node nodeObject = Instantiate(nodePrefab, new Vector3(0,y,0), Quaternion.identity) as Node;
                       nodeObject.nodeText.text = xmlNode.Attributes["name"].Value;
                       nodeObject.id = xmlNode.Attributes["name"].Value;
                       //skip other node attributes for now (branch_length, age_mya, etc)
                       nodes.Add(nodeObject.id, nodeObject);
                       statusText.text = "Loading Topology: Node " + nodeObject.id;
                       nodeCount++;
                       nodeCountText.text = "Nodes: " + nodeCount;
                   }
                   //create links
                   if (xmlNode.Name == "edge")
                   {
                       Link linkObject = Instantiate(linkPrefab, new Vector3(0, 0, 0), Quaternion.identity) as Link;
                       linkObject.id = xmlNode.Attributes["id"].Value;
                       linkObject.sourceId = xmlNode.Attributes["source"].Value;
                       linkObject.targetId = xmlNode.Attributes["target"].Value;
                       linkObject.status = xmlNode.Attributes["status"].Value;
                       links.Add(linkObject.id, linkObject);
                       statusText.text = "Loading Topology: Edge " + linkObject.id;
                       linkCount++;
                       linkCountText.text = "Edges: " + linkCount;
                   }
                   //every 100 cycles return control to unity
                   if (j % 100 == 0)
                       yield return true;
               }
           }
           //map node edges
           MapLinkNodes();
           statusText.text = "";
       }
       //Method for mapping links to nodes
       private void MapLinkNodes()
       {
           foreach (string key in links.Keys)
           {
               Link link = links[key] as Link;
               link.source = nodes[link.sourceId] as Node;
               link.target = nodes[link.targetId] as Node;
           }
       }
       void Start()
       {
           nodes = new Hashtable();
           links = new Hashtable();
           //initial stats
           nodeCountText = GameObject.Find("NodeCount").GetComponent<Text>();
           nodeCountText.text = "Nodes: 0";
           linkCountText = GameObject.Find("LinkCount").GetComponent<Text>();
           linkCountText.text = "Edges: 0";
           statusText = GameObject.Find("Status").GetComponent<Text>();
           statusText.text = "";
           StartCoroutine(LoadLayout());
       }
   }
}

Going to be great to get this up and running ;)




How to map/graph XML to 3d tree?

$
0
0

Edited:

The answer is to use Linq. For more info see https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/linq-to-xml

edited

Public member 'Reset' on type 'XmlNodeList' not found.

$
0
0

Hello All,

recently we have created new web server and moved our vb.net based web services to the new server(Windows 2012).

below is my code, in web service project i have referred Interop.MSXML2 dll(Microsoft XML, v6.0) when i publish in server then while the control reach at objNodeList.Reset() this line then im getting exception as "Public member 'Reset' on type 'XmlNodeList' not found" . Using Log only i found the line of exception

it was working perfectly in old server(Windows 2003), in new server i have installed asp.net 4.0, iis, also msxml6.msi from  link then also its not working so, installed MS office 2007 also but no luck.

experts please advise, 

Public Sub ParseResponse() Dim objNodeList Dim i Dim tmp1, tmp2, tmp3 Dim sha1hash Dim XMLRoot Dim XMLItem Log.WriteLog("1: ", MethodInfo.GetCurrentMethod().ToString() & "-" & Me.GetType().BaseType.FullName) objNodeList = XMLDoc.getElementsByTagName("response") Log.WriteLog("objNodeList: " & objNodeList.ToString(), MethodInfo.GetCurrentMethod().ToString() & "-" & Me.GetType().BaseType.FullName) responseFields.Add("timestamp", objNodeList.Item(0).getAttribute("timestamp")) 'Log.WriteLog("XMLDoc.getElementsByTagName('response'): " & XobjNodeList.Item(0).getAttribute("timestamp"), ' MethodInfo.GetCurrentMethod().ToString() & "-" & Me.GetType().BaseType.FullName) Log.WriteLog("before first reset: ", MethodInfo.GetCurrentMethod().ToString() & "-" & Me.GetType().BaseType.FullName)objNodeList.Reset()

Log.WriteLog("after first reset: ",
                             MethodInfo.GetCurrentMethod().ToString() & "-" & Me.GetType().BaseType.FullName)

-------------------- }



Upgrading to MSXML6.0 from MSXML 3.0 - Msxml2.FreeThreadedDOMDocument.6.0 and Msxml2.XSLTemplate.6.0 is not working.

$
0
0

Hi, We are in the process of upgrading MSXML 3.0 to MSXML 6.0 for one of our applications which has 82 pages.

All pages use DOM Documents. However 15 of these pages consisting of FreeThreaded and XSLTemplate are failing to run successfully after this upgrade. Below is the code:

    Set objXmlDoc = Server.CreateObject("MsXml2.DOMDocument.6.0")
    Set objXslDoc = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.6.0")

    Set objXSLTemplate = Server.CreateObject("Msxml2.XSLTemplate.6.0")

    objXSLTemplate.SetProperty "AllowXsltScript”, True
    objXSLTemplate.stylesheet = objXslDoc

Getting following error: Reference_to_undeclared_namespace_prefix:_'rs'.

Researched a little and see various queries - mostly unresolved about XSLT compatibility with MSXML6.dll

Tried following, but it didn't work either :(

objXslDoc.SetProperty "AllowXsltScript”, True

Tried various options but no rescue, please help!

Thank you so much in advance.

XML Signature incorrectly calculated - namespace declaration creates issues

$
0
0

hello,

We're facing a bug in our application when we try to sign an XML message. The bug only occurs when we declare the namespaces of the XML Message inside an XML Element. For these messages we receive an invalid SignatureValue while the DigestValue is correct. We have two "flavors" of the namespace declaration in our XML Messages and we have to respect that. See the structure in the flowing messages. The difference is in the declaration of thehead namespace.

1/

<?xml version="1.0" encoding="UTF-8"?><Message xmlns="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="myNamespace" xmlns:head="myHeader"><Header><head:elementA>someInfo</head:elementA><head:signature></head:signature></Header><Data><a:DataEntry>some data</a:DataEntry><a:DataEntry>some data</a:DataEntry></Data></Message>

2/

<?xml version="1.0" encoding="UTF-8"?><Message xmlns="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="myNamespace"><Header><head:elementA xmlns:head="myHeader">someInfo</head:elementA><head:signature xmlns:head="myHeader"></head:signature></Header><Data><a:DataEntry>some data</a:DataEntry><a:DataEntry>some data</a:DataEntry></Data></Message>


We use two transformers in the generation of our signature: XmlDsigEnvelopedSignatureTransform and XmlDsigC14NTransform.Enveloped because we are going to append the generated signature in the elementhead:Signature. The code is more or less like this (I've abstracted it a bit):

XmlDocument currentMessageDocument = new XmlDocument(); currentMessageDocument.PreserveWhitespace = false; currentMessageDocument.LoadXml(theXMLMessage); SignedXml signedMessage = new SignedXml(currentMessageDocument); Reference reference = new Reference(); reference.Uri = string.Empty; reference.DigestMethod = XmlSignatureConstants.Sha256DigestMethodUri; XmlDsigEnvelopedSignatureTransform envelopeTransform = new XmlDsigEnvelopedSignatureTransform(); reference.AddTransform(envelopeTransform); XmlDsigC14NTransform secondTransform = new XmlDsigC14NTransform(); reference.AddTransform(secondTransform); secondTransform.Algorithm = XmlSignatureConstants.XmlDsigC14N2006TransformUri; signedMessage.AddReference(reference); signedMessage.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigC14NTransformUrl; signedMessage.SignedInfo.SignatureMethod = XmlSignatureConstants.RsaSha256Uri; KeyInfo keyinfo = new KeyInfo(); KeyInfoX509Data x509Data = new KeyInfoX509Data(); x509Data.AddSubjectName(subjectname); x509Data.AddIssuerSerial(serialNumber); keyinfo.AddClause(x509Data); signedMessage.KeyInfo = keyinfo; signedMessage.ComputeSignature(); // This is specific to, signature has to look like that... XmlElement signedMessageElement = signedMessage.GetXml(); XmlNamespaceManager nsMgr = new XmlNamespaceManager(currentMessageDocument.NameTable); nsMgr.AddNamespace("dsig", "http://www.w3.org/2000/09/xmldsig#"); XmlNode x509DataNode = signedMessageElement.SelectSingleNode("dsig:KeyInfo/dsig:X509Data", nsMgr); List<XmlNode> existingx509Nodes = x509DataNode.ChildNodes.Cast<XmlNode>().ToList(); x509DataNode.RemoveAll(); List<XmlNode> existingSubjectNameNodes = existingx509Nodes.Where(n => n.LocalName == "X509SubjectName").ToList(); List<XmlNode> existingIssuerSerialNodes = existingx509Nodes.Where(n => n.LocalName == "X509IssuerSerial").ToList(); List<XmlNode> existingSubjectAndIssuerSerialNodes = existingSubjectNameNodes.Concat(existingIssuerSerialNodes).ToList(); foreach (var subjectOrIssuerNode in existingSubjectAndIssuerSerialNodes.Concat(existingx509Nodes.Except(existingSubjectAndIssuerSerialNodes))) { x509DataNode.AppendChild(subjectOrIssuerNode); } XmlNode importedSignatureNode = currentMessageDocument.ImportNode(signedMessageElement, true); XmlNode signatureNode = FindSignatureNode(theXMLMessage); signatureNode.AppendChild(importedSignatureNode.OuterXml);

return theXMLMessage;

This code works for the messages where the namespace declaration is done in the root (number 1). But when we do the same for the other XML Message (2), the signatureValue is incorrect. The DigestValue of the signature is correct in both cases if we compare it with another tool that generates the XML Signatures.

So DigestValues are always correct but the SignatureValue is incorrect when we use the XML Message with the namespace declaration inside the XML ElementSignature. When we decide to move the namespace declaration up to root level like XML Message 1, it works. But like I said, we cannot do this.

Any fresh ideas?

How to remove xmlns="http://www.ssp-uk.com/mqh/xsd/PanelSchemes" from xml using regex or anyother way

$
0
0
<Panel xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.ssp-uk.com/mqh/xsd/PanelSchemes">
   <PanelSchemes>
      <PanelScheme>
         <Name>CoreMotor.ZUB0</Name>
      </PanelScheme>
      <PanelScheme>
         <Name>CoreMotor.ZUB1</Name>
      </PanelScheme>
      <PanelScheme>
         <Name>CoreMotor.ZUB2</Name>
      </PanelScheme>
      <PanelScheme>
         <Name>CoreMotor.ZUB3</Name>
      </PanelScheme>
      <PanelScheme>
         <Name>CoreMotor.ZUB4</Name>
      </PanelScheme>
      <PanelScheme>
         <Name>CoreMotor.ZUB5</Name>
      </PanelScheme>
      <PanelScheme>
         <Name>CoreMotor.V7</Name>
      </PanelScheme>
   </PanelSchemes>
</Panel>

Compare 2 xml files ignoring elements/attribute order and list out only the differences in the report using c#

$
0
0

Hi All,

Iam new to this field and i was assigned with a challenging task. I have 2 xml files as shown below and i need to compare the Item Sections in both the xml files ignoring the elements/attribute order and display only the differences. Kindly help me on the same:

Source Xml:

<?xml version="1.0" encoding="utf-8"?><CUSTOMSEDI xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.dell.com/dbi/fsl/compliance/v1_0"><ASNNUM>SXMSEO180814001D</ASNNUM><ORDERS><ORDER><CUSID>743828552</CUSID><CUSADDRESS>KLS Tokyo Terminal3-2-31 Yashio, Shinagawa, TokyoJapanJapan</CUSADDRESS><ORDERNUM>979793524</ORDERNUM><CITY /><TIES><TIE><TIENUMBER>1</TIENUMBER><TIEQTY>1</TIEQTY><ITEMS><ITEM><ITEMNUMBER>KF3P2</ITEMNUMBER><ITEMQTY>1</ITEMQTY><ITEMDES>CUS,CBL,DNGL,HDMITOVGA,O,DBP</ITEMDES><ENMARKETINGDESC>Kit - Dell HDMI to VGA Adapter - S&amp;amp;P</ENMARKETINGDESC><TYPE>BASE</TYPE><PRICE>8.27</PRICE></ITEM><ITEM><ITEMNUMBER>60RD2</ITEMNUMBER><ITEMQTY>1</ITEMQTY><MOD>KF3P2</MOD><ITEMDES>CUS,CBL,DNGL,HDMITOVGA,O,DBP</ITEMDES><ENMARKETINGDESC>Kit - Dell HDMI to VGA Adapter - S&amp;amp;P</ENMARKETINGDESC><TYPE>INVOICE</TYPE><PRICE>8.27</PRICE></ITEM></ITEMS></TIE></TIES></ORDER><ORDER><CUSID>743828552</CUSID><CUSADDRESS>KLS Tokyo Terminal3-2-31 Yashio, Shinagawa, TokyoJapanJapan</CUSADDRESS><CUSCOUNTRY>JP</CUSCOUNTRY><CUSNAME>743828552</CUSNAME><ORDERNUM>979794834</ORDERNUM><CITY /><TIES><TIE><TIENUMBER>1</TIENUMBER><TIEQTY>1</TIEQTY><ITEMS><ITEM><ITEMNUMBER>K850M</ITEMNUMBER><ITEMQTY>1</ITEMQTY><ITEMDES>CUS,CORD,PWR,12A,2M,JPN,JMPR</ITEMDES><ENMARKETINGDESC>Kit - Jumper Cord, 12A,2M,C13/C14 (Japan)</ENMARKETINGDESC><TYPE>BASE</TYPE><PRICE>1.54</PRICE></ITEM><ITEM><ITEMNUMBER>T732H</ITEMNUMBER><ITEMQTY>1</ITEMQTY><MOD>K850M</MOD><ITEMDES>CUS,CORD,PWR,12A,2M,JPN,JMPR</ITEMDES><ENMARKETINGDESC>Kit - Jumper Cord, 12A,2M,C13/C14 (Japan)</ENMARKETINGDESC><TYPE>INVOICE</TYPE><PRICE>1.54</PRICE></ITEM></ITEMS></TIE></TIES></ORDER></ORDERS>

Final Xml:

<?xml version="1.0" encoding="utf-8"?><CUSTOMSEDI xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.dell.com/dbi/fsl/compliance/v1_0"><ASNNUM>SXMSEO180814001D</ASNNUM><ORDERS><ORDER><CUSID>744400014</CUSID><CUSADDRESS>KLS Tokyo Terminal3-2-31 Yashio, Shinagawa, TokyoJapan</CUSADDRESS><ORDERNUM>979794834</ORDERNUM><TIES><TIE><TIENUMBER>1</TIENUMBER><TIEQTY>1</TIEQTY><ITEMS><ITEM><ITEMNUMBER>T732H</ITEMNUMBER><ITEMQTY>1</ITEMQTY><MOD>K850M</MOD><ITEMDES>CUS,CORD,PWR,12A,2M,JPN,JMPR</ITEMDES><ENMARKETINGDESC>Kit - Jumper Cord, 12A,2M,C13/C14 (Japan)</ENMARKETINGDESC><TYPE>INVOICE</TYPE><PRICE>1.54</PRICE></ITEM><ITEM><ITEMNUMBER>K850M</ITEMNUMBER><ITEMQTY>1</ITEMQTY><ITEMDES>CUS,CORD,PWR,12A,2M,JPN,JMPR</ITEMDES><ENMARKETINGDESC>Kit - Jumper Cord, 12A,2M,C13/C14 (Japan)</ENMARKETINGDESC><TYPE>BASE</TYPE><PRICE>1.54</PRICE></ITEM></ITEMS></TIE></TIES></ORDER><ORDER><CUSID>743138972</CUSID><CUSADDRESS>KLS Tokyo Terminal3-2-31 Yashio, Shinagawa, TokyoJapan</CUSADDRESS><ORDERNUM>979793524</ORDERNUM><TIES><TIE><TIENUMBER>1</TIENUMBER><TIEQTY>1</TIEQTY><ITEMS><ITEM><ITEMNUMBER>60RD2</ITEMNUMBER><ITEMQTY>1</ITEMQTY><MOD>KF3P2</MOD><ITEMDES>CUS,CBL,DNGL,HDMITOVGA,O,DBP</ITEMDES><ENMARKETINGDESC>Kit - Dell HDMI to VGA Adapter - S&amp;P</ENMARKETINGDESC><TYPE>INVOICE</TYPE><PRICE>8.27</PRICE></ITEM><ITEM><ITEMNUMBER>KF3P2</ITEMNUMBER><ITEMQTY>1</ITEMQTY><ITEMDES>CUS,CBL,DNGL,HDMITOVGA,O,DBP</ITEMDES><ENMARKETINGDESC>Kit - Dell HDMI to VGA Adapter - S&amp;P</ENMARKETINGDESC><TYPE>BASE</TYPE><PRICE>8.27</PRICE></ITEM></ITEMS></TIE></TIES></ORDER></ORDERS>

Thanks,

Ram


ram


how to change a node during runtime?

$
0
0

 Hi, i am a XML beginner and would like to change the node <Tabelle1> during runtime

if a variable has a specific value, then it should be <Tabelle1>

if a variable has a another specific value, then it should be <Tabelle2>

thanks for helping out.

Code like this:

        Dim filename = "C:\CG_Sports\Fussball\tabellen.xml"
        Dim welchetabelle As String
           Try
            Dim Contactlist As XDocument = XDocument.Load(filename)
            For Each contact As XElement In Contactlist...<Tabelle1>
                titel_text.Text = contact.Element("titel")
                template_text.Text = contact.Element("templatename")

                For i = 1 To 30
                    Controls.Item("r" & i).Text = contact.Element("col" + Trim(i) + "1")
                    Controls.Item("nr" & i).Text = contact.Element("col" + Trim(i) + "2")
                    Controls.Item("name" & i).Text = contact.Element("col" + Trim(i) + "3")
                    Controls.Item("vorname" & i).Text = contact.Element("col" + Trim(i) + "4")
                    Controls.Item("pos" & i).Text = contact.Element("col" + Trim(i) + "5")
                    Controls.Item("d" & i).Text = contact.Element("col" + Trim(i) + "6")
                    Controls.Item("dd" & i).Text = contact.Element("col" + Trim(i) + "7")
                    Controls.Item("ddd" & i).Text = contact.Element("col" + Trim(i) + "8")
                Next
                For i = 1 To 8
                    Controls.Item("feld" & i).Text = contact.Element("feld" + Trim(i))
                Next
            Next
        Catch ex As System.IO.IOException
            MessageBox.Show("File nicht vorhanden")
        Catch ex As NullReferenceException
            MessageBox.Show("NullReferenceException: " & ex.Message)
            MessageBox.Show("Stack Trace: " & vbCrLf & ex.StackTrace)
        Catch ex As Exception
        End Try

MSXML 4.0 SP3 future

$
0
0

I'm using MS XDR XMLs and MSXML 4.0 in my projects since 2002. In the past, there were security issues with MSXML 4.0 reported and fixed by Microsoft, last fixes released with the version MSXML 4.0 SP3. In release notes of the latter following is stated:"Both MSXML 4.0 SP2 and SP3 are entering maintenance mode now, therefore no new functionality and performance improvement will be made in MSXML 4.0, servicing will be restricted to high impact security issues. There are no plans for future MSXML 4.0 service packs." For my understanding, this means following: a) there're no new known issues for the MSXML 4.0 SP3; b) If there will emerge any security issue, Microsoft will address it (quoting from the release notes: "servicing will be restricted to high impact security issues");

Therefore, my software using MSXML 4.0 SP3 doesn't necessarily require costly reengineering resulting from a migration of the software from the MSXML 4.0 SP3 to the MSXML 6.0.

My customers would like to have a clear statement from Microsoft regarding this, as the release notes I am referring to is 4 years old. Is the statement "servicing will be restricted to high impact security issues" still standing for the MSXML4.0 SP3?

using XSLT to compare xml files

$
0
0
Hello experts,
i am kinda new to thisstuff, i wanted to know how to compare two xml files using  xslt and display another xml file only 
with the differences in the xml file: 

xml1:

    <?xml version="1.0" encoding="utf-8"?>
    <ASNNUM>SXMSEO180814001D</ASNNUM>
      <ORDERS>
         <ORDER>
          <CUSNAME>743828553</CUSNAME>
          <ORDERNUM>979793524</ORDERNUM>
          <CITY />
          <TIES>
            <TIE>
              <TIENUMBER>1</TIENUMBER>
              <TIEQTY>1</TIEQTY>
              <ITEMS>
                 <ITEM>
                  <ITEMNUMBER>KF3P2</ITEMNUMBER>
                  <ITEMQTY>1</ITEMQTY>
                  <PRICE>8.27</PRICE>
                </ITEM>
                <ITEM>
                  <ITEMNUMBER>60RD2</ITEMNUMBER>
                  <ITEMQTY>1</ITEMQTY>
                  <PRICE>8.27</PRICE>
                </ITEM>
              </ITEMS>
            </TIE>
          </TIES>
    </ORDER>
    <ORDER>
          <CUSNAME>743828552</CUSNAME>
          <ORDERNUM>979794834</ORDERNUM>
          <CITY />
          <TIES>
            <TIE>
              <TIENUMBER>1</TIENUMBER>
              <TIEQTY>1</TIEQTY>
              <ITEMS>
                <ITEM>
                  <ITEMNUMBER>K850M</ITEMNUMBER>
                  <ITEMQTY>1</ITEMQTY>
                  <PRICE>1.54</PRICE>
                </ITEM>
                <ITEM>
                  <ITEMNUMBER>T732H</ITEMNUMBER>
                  <ITEMQTY>1</ITEMQTY>
                  <PRICE>1.54</PRICE>
                </ITEM>
              </ITEMS>
            </TIE>
          </TIES>
        </ORDER>
      </ORDERS>

XML2:

    <?xml version="1.0" encoding="utf-8"?>
      <ASNNUM>SXMSEO180814001D</ASNNUM>
       <ORDERS>
         <ORDER>
          <CUSID>744400014</CUSID>
          <ORDERNUM>979794834</ORDERNUM>
          <TIES>
            <TIE>
              <TIENUMBER>1</TIENUMBER>
              <TIEQTY>1</TIEQTY>
              <ITEMS>
                <ITEM>
                  <ITEMNUMBER>T732H</ITEMNUMBER>
                  <ITEMQTY>1</ITEMQTY>
                  <PRICE>1.54</PRICE>
                </ITEM>
                <ITEM>
                  <ITEMNUMBER>K850M</ITEMNUMBER>
                  <ITEMQTY>1</ITEMQTY>
                  <PRICE>1.54</PRICE>
                </ITEM>
              </ITEMS>
            </TIE>
          </TIES>
        </ORDER>
    <ORDER>
          <CUSID>743138972</CUSID>
          <CUSADDRESS>KLS Tokyo Terminal3-2-31 Yashio, Shinagawa, TokyoJapan</CUSADDRESS>
          <ORDERNUM>979793524</ORDERNUM>
          <TIES>
            <TIE>
              <TIENUMBER>1</TIENUMBER>
              <TIEQTY>1</TIEQTY>
              <ITEMS>
                <ITEM>
                  <ITEMNUMBER>60RD2</ITEMNUMBER>
                  <ITEMQTY>1</ITEMQTY>
                  <PRICE>8.27</PRICE>
                </ITEM>
            <ITEM>
                  <ITEMNUMBER>KF3P2</ITEMNUMBER>
                  <ITEMQTY>25</ITEMQTY>
                  <PRICE>8.27</PRICE>
                </ITEM>
              </ITEMS>
            </TIE>
          </TIES>
        </ORDER>
      </ORDERS>

Thanks,
Ram

ram

How to Canonicalize Xml Document for Hashing

$
0
0
Hello,

Does anyone know how to do this.  The algorithm that I need to use is System.Security.Cryptography.Xml.XmlDsigExcC14NTransform and the class reference notes state the following: "You are required to create a new instance of a canonicalization transform class only when you want to manually hash an XML document or use your own canonicalization algorithm." 

An example of what I am doing and only seeing a node the describes the transformation as a result is below.

dList = dDoc.GetElementsByTagName("Forms");

if (dList.Count > 0)
{
    exclusive.LoadInnerXml(dList);                      
    dElement = exclusive.GetXml();
    dRet.hash = dElement.InnerXml;
}

Now what I am trying to do all this is for a creating a hash of the canonical xml of one child branch of an xml document.

I have an input document and want to take once brach of the tree structure and hash it.  However it has to be in an exclusive canonical form prior to gernerating the hash of it.  To my knowledge this is not generating a digital signature which is great for an example but does not show how to use the class manually to extract transformed xml.

Anything else you need to help in this please let me know.

Thanks


Use XSLT to compare multiple xml and list the differences in another xml file

$
0
0
Hello experts,
i wanted to know how to compare two xml files using  C# or xslt and display another xml file only 
with the differences in the xml file:

xml1:
<ORDERS><ORDER><ORDERNUM>979793524</ORDERNUM><TIES><TIE><TIENUMBER>1</TIENUMBER><ITEMS><ITEM><ITEMNUMBER>KF3P2</ITEMNUMBER><ITEMQTY>1</ITEMQTY></ITEM><ITEM><ITEMNUMBER>60RD2</ITEMNUMBER><ITEMQTY>1</ITEMQTY></ITEM></ITEMS></TIE></TIES></ORDER><ORDER><ORDERNUM>979794834</ORDERNUM><TIES><TIE><TIENUMBER>1</TIENUMBER><ITEMS><ITEM><ITEMNUMBER>K850M</ITEMNUMBER><ITEMQTY>1</ITEMQTY></ITEM><ITEM><ITEMNUMBER>T732H</ITEMNUMBER><ITEMQTY>1</ITEMQTY></ITEM></ITEMS></TIE></TIES></ORDER></ORDERS>



XML2:
<ORDERS><ORDER><ORDERNUM>979794834</ORDERNUM><TIES><TIE><TIENUMBER>1</TIENUMBER><ITEMS><ITEM><ITEMNUMBER>T732H</ITEMNUMBER><ITEMQTY>1</ITEMQTY></ITEM><ITEM><ITEMNUMBER>K850M</ITEMNUMBER><ITEMQTY>10</ITEMQTY></ITEM></ITEMS></TIE></TIES></ORDER><ORDER><ORDERNUM>979793524</ORDERNUM><TIES><TIE><TIENUMBER>1</TIENUMBER><TIEQTY>1</TIEQTY><ITEMS><ITEM><ITEMNUMBER>60RD2</ITEMNUMBER><ITEMQTY>1</ITEMQTY></ITEM><ITEM><ITEMNUMBER>KF3P2</ITEMNUMBER><ITEMQTY>25</ITEMQTY></ITEM></ITEMS></TIE></TIES></ORDER></ORDERS>


  
 
Expected Output:
 
 
<ORDERNUM>979793524</ORDERNUM><ITEMNUMBER>KF3P2</ITEMNUMBER><ITEMQTY>25</ITEMQTY><ORDERNUM>979794834</ORDERNUM><<ITEMNUMBER>K850M</ITEMNUMBER><ITEMQTY>10</ITEMQTY>


   

ram


ram

xsd schema for xml

$
0
0

Hi,

I have existing xml schema which I need to modify to get the following data.

XSD Schema:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema id="sschema" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="MSG" type="MessageType"/>
  <xsd:complexType name="MessageType">
    <xsd:choice>
        <xsd:element name="TRANSACTIONS" type="TransactionsType" />
        <xsd:element name="CLIENTS" type="ClientsType" />        
    </xsd:choice>
    <xsd:attribute name="MessageID" type="xsd:string" use="required"/>
    <xsd:attribute name="ApplicationName" type="xsd:string" use="required"/>
    <xsd:attribute name="MessageCreationTime" type="xsd:dateTime" use="required"/>
  </xsd:complexType>
  <xsd:complexType name="TransactionsType">
    <xsd:sequence minOccurs="1" maxOccurs="unbounded">
      <xsd:element name="Transaction" type="TransactionType"/>
    </xsd:sequence>
    <xsd:attribute name="ChildCount" type="xsd:int" />
  </xsd:complexType>
  <xsd:complexType name="ClientsType">
    <xsd:sequence minOccurs="1" maxOccurs="unbounded">
      <xsd:element name="CLIENT" type="ClientType"/>
    </xsd:sequence>
    <xsd:attribute name="ChildCount" type="xsd:int" />
  </xsd:complexType>
  <xsd:complexType name="TransactionType">
    <xsd:sequence>
      <xsd:element name="ACTION" type="ActionTypes" minOccurs="1" maxOccurs="1" />
      <xsd:element name="ACCOUNTS" minOccurs="1" maxOccurs="1">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="ACCOUNT" minOccurs="1" >
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="DEBIT_ACCOUNT" type="xsd:short" />
                  <xsd:element name="CREDIT_ACCOUNT" type="xsd:short" />
                  <xsd:element name="AMOUNT" type="xsd:string" />
                  <xsd:element name="ID" type="xsd:int" />             
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
   </xsd:sequence>
  </xsd:complexType>
  <xsd:simpleType name="ActionTypes">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="Add"/>
      <xsd:enumeration value="Update"/>
      <xsd:enumeration value="Delete"/>
    </xsd:restriction>
  </xsd:simpleType>
</xsd:schema>

My xml for above schema for transactions looks likes this:

<TRANSACTIONS ChildCount='1'>
  <TRANSACTION>

       ...........

       ......

   </TRANSACTION>

</TRANSACTIONS>

Now they want me to add another element in transactions element like this:

<TRANSACTIONS ChildCount='1'>
  <SOURCE_TRANSACTION>

       ...........

       ......

   </SOURCE_TRANSACTION>

   

   <DEST_TRANSACTION>

       ...........

       ......

   </DEST_TRANSACTION>

</TRANSACTIONS>

How can I add another element to 'Transactions' element because Transactions element is defined as type 'TransactionType'.

Dest_Transaction has different data structure. Both Source_transaction and Dest_transaction should be placed under 'Transactions' parent element.

Thank You

C# SignedXml and external data in Reference

$
0
0

Hello,

I am trying to use C# and SignedXml to sign (and verify) some external data like this:

        static string flXML = @"C:\Temp\Example.xml";
        static string flSignedXML = @"C:\Temp\SignedExample.xml";

        static void Main(string[] args)
        {
            try
            {
                CryptoConfig.AddAlgorithm(typeof(RSAPKCS1SHA256SignatureDescription), "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");

                // Generate a signing key.
                RSACryptoServiceProvider Key = new RSACryptoServiceProvider();

                SignXmlFile(flXML, flSignedXML, Key);

                bool result = VerifyXmlFile(flSignedXML, Key);

                if (result)
                    Console.WriteLine("The XML signature is valid.");
                else
                    Console.WriteLine("The XML signature is not valid.");
            }
            catch (CryptographicException e)
            {
                Console.WriteLine(e.Message);
            }
        }

        public static void SignXmlFile(string FileName, string SignedFileName, RSA Key)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(new XmlTextReader(FileName));

            SignedXml signedXml = new SignedXml(doc);
            signedXml.SigningKey = Key;
            signedXml.SignedInfo.SignatureMethod = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";

            // Create a reference to be signed.
            Reference reference = new Reference();
            reference.Uri = "";
            reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
            reference.AddTransform(new XmlDsigExcC14NTransform());
            reference.DigestMethod = "http://www.w3.org/2001/04/xmlenc#sha256";
            signedXml.AddReference(reference);

            // Add the extgernal data to be signed to the SignedXml object.
            {
                byte[] Content = System.Text.Encoding.UTF8.GetBytes("12345qwert67890asdfg");
                Stream stream = new MemoryStream(Content);
                Reference reference2 = new Reference(stream);
                reference2.Uri = "cid:xml-sample";
                reference2.DigestMethod = "http://www.w3.org/2001/04/xmlenc#sha256";
                signedXml.AddReference(reference2);
            }

            signedXml.ComputeSignature();
            XmlElement xmlDigitalSignature = signedXml.GetXml();
            doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, true));
            if (doc.FirstChild is XmlDeclaration)
            {
                doc.RemoveChild(doc.FirstChild);
            }

            XmlTextWriter xmltw = new XmlTextWriter(SignedFileName, new UTF8Encoding(false));
            doc.WriteTo(xmltw);
            xmltw.Close();
        }

        public static Boolean VerifyXmlFile(String Name, RSA Key)
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(Name);

            SignedXml signedXml = new SignedXml(xmlDocument);
            XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");
            signedXml.LoadXml((XmlElement)nodeList[0]);

            {
                byte[] Content = System.Text.Encoding.UTF8.GetBytes("12345qwert67890asdfg");
                Stream stream = new MemoryStream(Content);

                Reference reference2 = new Reference(stream);
                reference2.Uri = "cid:xml-sample";
                reference2.DigestMethod = "http://www.w3.org/2001/04/xmlenc#sha256";
                signedXml.AddReference(reference2);
            }

            signedXml.SigningKey = Key;
            // Check the signature and return the result.
            return signedXml.CheckSignature();
        }

and CheckSignature always returns false!

Input XML:

<MyElement xmlns="samples"><PayloadInfo><PartInfo href="cid:xml-sample">                        </PartInfo></PayloadInfo></MyElement>


Signed XML looks OK to me:

<MyElement xmlns="samples"><PayloadInfo><PartInfo href="cid:xml-sample"></PartInfo></PayloadInfo><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /><Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" /><DigestValue>pfmPOwgPEutZr/DP1U3KoBO/7dHnq0PlJm+f0Cx0HLE=</DigestValue></Reference><Reference URI="cid:xml-sample"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" /><DigestValue>2QmqZagw72ea4w4UXVhSt5I0AJ7lcUx5rRsvQMVnz4g=</DigestValue></Reference></SignedInfo><SignatureValue>Y/cHki0vVO2CNLHdSaGsTRVueSH/OsYmCspLByKnlcK8XM7kjcFiSuocxz8xsUVv3bk8LtgRMtDK3eZQr8WmKSBDkgEWmVF88xAArDPm0DJVZn89RX6rAIvcitnDXG/oAOwTxyW9wQoKzWqg3fyrCq4o0g2J0zr8vcPmQVrgdJg=</SignatureValue></Signature></MyElement>

Beautified:

<MyElement xmlns="samples"><PayloadInfo><PartInfo href="cid:xml-sample"></PartInfo></PayloadInfo><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /><Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" /><DigestValue>pfmPOwgPEutZr/DP1U3KoBO/7dHnq0PlJm+f0Cx0HLE=</DigestValue></Reference><Reference URI="cid:xml-sample"><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" /><DigestValue>2QmqZagw72ea4w4UXVhSt5I0AJ7lcUx5rRsvQMVnz4g=</DigestValue></Reference></SignedInfo><SignatureValue>Y/cHki0vVO2CNLHdSaGsTRVueSH/OsYmCspLByKnlcK8XM7kjcFiSuocxz8xsUVv3bk8LtgRMtDK3eZQr8WmKSBDkgEWmVF88xAArDPm0DJVZn89RX6rAIvcitnDXG/oAOwTxyW9wQoKzWqg3fyrCq4o0g2J0zr8vcPmQVrgdJg=</SignatureValue></Signature></MyElement>

If I do not include second Reference (external data) CheckSignature will return true.

Does anyone knows what I am doing wrong ?

Thanks,

Sasa Kajic



Escape backslash in XML and split as separate xml node using XSLT

$
0
0
Hello, I am looking for an XML conversion to a desired output.

Input XML:    


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<properties>
    <entry>
        <key>first_node/P_NODE</key>
        <value>
            <genericData>
                <identifier>first_node/P_NODE</identifier>
                <properties>
                    <entry>
                        <key>second_node</key>
                        <value>2</value>
                    </entry>
                    <entry>
                        <key>third_node/fourth_node/fifth_node</key>
                        <value>345</value>
                    </entry>
                    <entry>
                        <key>sixth_node/seventh_node</key>
                        <value>67</value>
                    </entry>
                    <entry>
                        <key>eigth_node</key>
                        <value>8</value>
                    </entry>
                    <entry>
                        <key>ninth_node</key>
                        <value>
                            <genericData>
                                <identifier>ninth_node</identifier>
                                <properties>
                                    <entry>
                                        <key>tenth_node</key>
                                        <value>10</value>
                                    </entry>
                                    <entry>
                                        <key>eleventh_node/twelveth_node</key>
                                        <value>1112</value>
                                    </entry>
                                </properties>
                            </genericData>
                        </value>
                    </entry>
                </properties>
            </genericData>
        </value>
</entry>
    <entry>
        <key>tirteenth_node</key>
        <value>
            <genericData>
                <identifier>tirteenth_node</identifier>
                <properties>
                    <entry>
                        <key>fourteenth_node</key>
                        <value>14</value>
                    </entry>
                    <entry>
                        <key>fifteenth_node/sixteenth_node</key>
                        <value>1516</value>
                    </entry>
                </properties>
            </genericData>
        </value>
    </entry>
    <entry>
        <key>seventeeth_node/eighteenth_node</key>
        <value>1718</value>
    </entry>
    <entry>
        <key>nineteenth_node/twenth_node</key>
        <value>1920</value>
    </entry>
    <entry>
        <key>twentyfirst_node</key>
        <value>21</value>
    </entry>

</properties>


Desired Output:

<properties>
    <first_node>
        <P_NODE>
            <second_node>2</second_node>
            <third_node>
                <fourth_node>
                    <fifth_node>345</fifth_node>
                </fourth_node>
            </third_node>
            <sixth_node>
                <seventh_node>67</seventh_node>
            </sixth_node>
            <eigth_node>8</eigth_node>
            <ninth_node>
                <tenth_node>10</tenth_node>
                <eleventh_node>
                    <twelveth_node>1112</twelveth_node>
                </eleventh_node>
            </ninth_node>
        </P_NODE>
    </first_node>
    <tirteenth_node>
        <fourteenth_node>14</fourteenth_node>
        <fifteenth_node>
            <sixteenth_node>1516</sixteenth_node>
        </fifteenth_node>
    </tirteenth_node>
    <seventeeth_node>
        <eighteenth_node>1718</eighteenth_node>
    </seventeeth_node>
    <nineteenth_node>
        <twenth_node>1920</twenth_node>
    </nineteenth_node>
    <twentyfirst_node>21</twentyfirst_node>
</properties>


Need and XSLT stylesheet to get the desired output. Kindly Help.



xml schema with 2 root elements

$
0
0

Hi,

I have schema like this:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema id="MessageSchema" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="MESSAGE" type="MessageType"/>
  <xsd:complexType name="MessageType">
    <xsd:choice>
      <xsd:element name="TRNS" type="TrnType" />
      <xsd:element name="CLNTS" type="ClntsType" />
      <xsd:element name="ACT" type="ActType"  />      
       <xsd:element name="POSS" type="PossType" />
    </xsd:choice>    
    <xsd:attribute name="MessageID" type="xsd:string" use="required"/>
    <xsd:attribute name="ApplicationName" type="xsd:string" use="required"/>
    <xsd:attribute name="MessageCreationTime" type="xsd:dateTime" use="required"/>
  </xsd:complexType>

............

..............

<xsd:complexType name="TranType">
    <xsd:choice minOccurs="1" maxOccurs="unbounded">
      <xsd:element name="TRANSACTION" type="TransactionType"/>      
    </xsd:choice>
    <xsd:attribute name="ChildCount" type="xsd:int" />
  </xsd:complexType>
  .........
  <xsd:complexType name="PositionsType">
    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="POSITION" type="PositionType"/>    </xsd:choice>

With this schema, my xml allows only one root under Message. Like this:

<MESSAGE.. attributes>

<TRANS>

<TRANSACTION>... </TRANSACTION>

</TRANS>

</MESSAGE>

BUT I need to allow TRANS AND POS to go either as one or 2. Rest only one at a time

<MESSAGE.. attributes>

<TRANS>

<TRANSACTION>... </TRANSACTION>

</TRANS>

<POSS>

<POSITION>...</POSITION>

</POSS>

</MESSAGE>

How can I do it in schema.

Thank You

Use xsd.exe to create XSD from XML without DataSet stuff

$
0
0

When I use the xsd.exe tool to create an XSD from an XML I get an XSD file with namespaces, tags and attributes for creating classes that use the DataSet class and related classes.

For example, with the following XML (file named sample.xml):

<?xml version="1.0"?><people  xmlns="http://tempuri.org/transformxml.xsd"><person born="1912" died="1954"><name><first_name>Alan</first_name><last_name>Turing</last_name></name><location>London</location><profession>computer scientist</profession><profession>mathematician</profession><profession>cryptographer</profession></person><person born="1918" died="1988"><name><first_name>Richard</first_name><middle_initial>M</middle_initial><last_name>Feynman</last_name></name><location>New York</location><profession>physicist</profession><hobby>Playing the bongoes</hobby></person></people>

If I do "xsd sample.xml" then I get:

<?xml version="1.0" encoding="utf-8"?><xs:schema id="people" targetNamespace="http://tempuri.org/transformxml.xsd" xmlns:mstns="http://tempuri.org/transformxml.xsd" xmlns="http://tempuri.org/transformxml.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"><xs:element name="people" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element name="person"><xs:complexType><xs:sequence><xs:element name="location" type="xs:string" minOccurs="0" msdata:Ordinal="1" /><xs:element name="hobby" type="xs:string" minOccurs="0" msdata:Ordinal="2" /><xs:element name="name" minOccurs="0" maxOccurs="unbounded"><xs:complexType><xs:sequence><xs:element name="first_name" type="xs:string" minOccurs="0" /><xs:element name="middle_initial" type="xs:string" minOccurs="0" /><xs:element name="last_name" type="xs:string" minOccurs="0" /></xs:sequence></xs:complexType></xs:element><xs:element name="profession" nillable="true" minOccurs="0" maxOccurs="unbounded"><xs:complexType><xs:simpleContent msdata:ColumnName="profession_Text" msdata:Ordinal="0"><xs:extension base="xs:string"></xs:extension></xs:simpleContent></xs:complexType></xs:element></xs:sequence><xs:attribute name="born" form="unqualified" type="xs:string" /><xs:attribute name="died" form="unqualified" type="xs:string" /></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema>


I don't want any of that stuff in bold; the msdata stuff. The problem is that when I generate classes from an XSD like that I get code for use with the DataSet class and such and I want just plain classes. I could use some other tool to generate an XSD from XML but if the Microsoft XSD tool can be configured to do what I need then I want to know how.



Sam Hobbs
SimpleSamples.Info


Simple multi replace function in XSLT

$
0
0

I'm new to XSLT, but have a nicely working script that I'd like to refine by replacing numeric values for field 'Type' with related strings in the result. In JavaScript, I'd use a switch function but I need the equivalent in XSL

My Table Definition:

  <table>
  <tr bgcolor="#6FB6E2">
      <th>User Field</th>
      <th>Name</th>
      <th>Identifier</th>
      <th>Type</th>
      <th>Parameters</th>
      <th>Locked</th>
      <th>Mandatory</th>
  </tr>
  <xsl:for-each select="PREFERENCES/USERCOLUMNS/userColumn">
            <tr>
              <td>USER<xsl:value-of select="@index"/></td>
              <td><xsl:value-of select="@name"/></td>
              <td><xsl:value-of select="@identifier"/></td>
              <td><xsl:value-of select="@type"/></td>
              <td><xsl:value-of select="@parameters"/></td>
              <td><xsl:value-of select="@locked"/></td>
              <td><xsl:value-of select="@mandatory"/></td>
              </tr>
    </xsl:for-each>
  </table>

My replacement value sets for field "type":

From: ('1', '2', '3', '4', '5')

To: ('Grouping', 'Multi Grouping', 'Hierarchy', 'Multi Hierarchy', 'Linked Hierarchy')

My Sample XML:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<PREFERENCES>
<USERCOLUMNS count="168">
  <userColumn index="33" identifier="user.custom.language" name="Language" locked="false" mandatory="false" type="1"/>
  <userColumn index="41" identifier="user.basic.host.presenter" name="Host/Presenter" locked="false" mandatory="false" type="2"/>
  <userColumn index="42" identifier="user.basic.subject.line" name="Subject/Line" locked="false" mandatory="false" type="3"/>
  <userColumn index="54" identifier="user.extended.best.take" name="Best Take" parameters="YES&#10;No&#10;Possible" locked="false" mandatory="false" type="4"/>
  <userColumn index="55" identifier="user.basic.shoot.date" name="Shoot Date" locked="false" mandatory="false" type="5"/>
 </USERCOLUMNS>
</PREFERENCES>

As a bonus question, the "parameters" field includes line feeds as separators for multiple values, but they are not being read as such. In the fourth line, userColumn index="54" the "parameters field has a value of "YES&#10;No&#10;Possible" which should be three lines showing a word on three lines... Is there anyway to have the table word wrap so that the line feeds are displayed correctly?

XSLT split string on unicode line feed characters

$
0
0

New to XSLT, and have an XML field with unicode line feed characters (&#10) which I need to display with HTML line breaks. 

In my XML there is a "parameters" field includes line feeds as separators for multiple values, but they are not being read as such. In the fourth line, userColumn index="54" the "parameters" field has a value of "YES&#10;No&#10;Possible" which should be output as three lines showing a word on each line... 

My Table Definition:

  <table>
  <tr bgcolor="#6FB6E2">
      <th>User Field</th>
      <th>Name</th>
      <th>Identifier</th>
      <th>Type</th>
      <th>Parameters</th>
      <th>Locked</th>
      <th>Mandatory</th>
  </tr>
  <xsl:for-each select="PREFERENCES/USERCOLUMNS/userColumn">
            <tr>
              <td>USER<xsl:value-of select="@index"/></td>
              <td><xsl:value-of select="@name"/></td>
              <td><xsl:value-of select="@identifier"/></td>
              <td><xsl:value-of select="@type"/></td>
              <td><xsl:value-of select="@parameters"/></td>
              <td><xsl:value-of select="@locked"/></td>
              <td><xsl:value-of select="@mandatory"/></td>
              </tr>
    </xsl:for-each>
  </table>

My Sample XML:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<PREFERENCES>
<USERCOLUMNS count="168">
  <userColumn index="33" identifier="user.custom.language" name="Language" locked="false" mandatory="false" type="1"/>
  <userColumn index="41" identifier="user.basic.host.presenter" name="Host/Presenter" locked="false" mandatory="false" type="2"/>
  <userColumn index="42" identifier="user.basic.subject.line" name="Subject/Line" locked="false" mandatory="false" type="3"/>
  <userColumn index="54" identifier="user.extended.best.take" name="Best Take" parameters="YES&#10;No&#10;Possible" locked="false" mandatory="false" type="4"/>
  <userColumn index="55" identifier="user.basic.shoot.date" name="Shoot Date" locked="false" mandatory="false" type="5"/>
 </USERCOLUMNS>
</PREFERENCES>

Proposed XSLT from contributor Viorel_ ALMOST works...:

<xsl:template name="show-lines">
  <xsl:param name="text"/>
  <xsl:choose>
    <xsl:when test="contains($text, '&#10;')">
      <xsl:value-of select="substring-before($text, '&#10;')"/>
        <br/>
      <xsl:call-template name="show-lines">
        <xsl:with-param name="text" select="substring-after($text, '&#10;')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$text"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

The parameters value shows up in HTML as:
Sunny0;Cloudy0;Rain0;Wind0;Snow0;Ice0;Fog

But it should show up as:

Sunny
Cloudy
Rain
Wind
Snow
Ice
Fog

Is there anyway to have the table word wrap on output so that line feeds are correctly interpreted and displayed as breaks? Thanks!!


Viewing all 935 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>