Get Attribute of xsf:xDocumentClass Node in manifest.xsf - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Get Attribute of xsf:xDocumentClass Node in manifest.xsf

Last post 09-27-2010 07:41 AM by colecg. 19 replies.
Page 1 of 2 (20 items) 1 2 Next >
Sort Posts: Previous Next
  • 08-21-2009 01:03 PM

    Get Attribute of xsf:xDocumentClass Node in manifest.xsf

    How would I get the "name" attribute from the manifest.xsf file using C#?

    Example: name="urn:schemas-microsoft-com:office:infopath:FormName:-myXSD-2008-06-30T14-56-08"

    I want to retrieve "urn:schemas-microsoft-com:office:infopath:FormName:-myXSD-2008-06-30T14-56-08"

  • 08-21-2009 01:04 PM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

     More specifically, the node that I need to retrieve an attribute from is

    <xsf:xDocumentClass solutionFormatVersion="2.0.0.0" solutionVersion="1.0.0.575" productVersion="12.0.0" requireFullTrust="yes" name="urn:schemas-microsoft-com:office:infopath:FormName:-myXSD-2008-06-30T14-56-08" xmlns:xsf="http://schemas.microsoft.com/office/infopath/2003/solutionDefinition" xmlns:xsf2="http://schemas.microsoft.com/office/infopath/2006/solutionDefinition/extensions" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xdUtil="http://schemas.microsoft.com/office/infopath/2003/xslt/Util" xmlns:xdXDocument="http://schemas.microsoft.com/office/infopath/2003/xslt/xDocument" xmlns:xdMath="http://schemas.microsoft.com/office/infopath/2003/xslt/Math" xmlns:xdDate="http://schemas.microsoft.com/office/infopath/2003/xslt/Date" xmlns:xdExtension="http://schemas.microsoft.com/office/infopath/2003/xslt/extension" xmlns:xdEnvironment="http://schemas.microsoft.com/office/infopath/2006/xslt/environment" xmlns:xdUser="http://schemas.microsoft.com/office/infopath/2006/xslt/User" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-06-30T14:56:08" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields" xmlns:tns="http://rjbtech.com/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

  • 08-21-2009 06:49 PM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

    In the 2007 C# object model, this.Template.Manifest is a reference to an XPathNavigator for the manifest.  You can use this like:

                XPathNavigator name = this.Template.Manifest.SelectSingleNode("@name", NamespaceManager);

    to get the name attribute.  I believe there will be no name attribute if the form is unpublished so this will not work in preview mode.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-25-2009 12:18 PM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

    Thanks Jimmy but I am trying to modify manifest.xsf from a SharePoint Feature receiver rather than InfoPath code behind. How would I go about modifying the xml file in a more generic way?

    It may be round-about but my process is this:

    1.  Activate Feature 
    2. Code will extract files from xsn/cab file 12\template\features\customform\customform.xsn
    3. need to modify name="urn..." attribute on nodes in manifest.xsf and template.xml
    4. save files
    5. repackage into xsn file
    Step 3 is the only part that I am having trouble with.

    Thank you
  • 08-25-2009 01:02 PM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

     Yes, that's pretty much the best that can be done.  For the middle step, you can write a .NET tool to:

    • Open up the manifest.xsf and template.xml files using the XmlDocument class.
    • Make the necessary modifications using the XmlDocument object's access methods.
    • Re-save the files using the Save() method.
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-25-2009 01:16 PM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

    Middle step seems like it should be easy but that's what I'm having a hard time with

    How do I change the name="urn:schemas-microsoft-com:office:infopath:FormName:-myXSD-2008-06-30T14-56-08" attribute for the below xml node?

    <xsf:xDocumentClass solutionFormatVersion="2.0.0.0" solutionVersion="1.0.0.575" productVersion="12.0.0" requireFullTrust="yes" name="urn:schemas-microsoft-com:office:infopath:FormName:-myXSD-2008-06-30T14-56-08" xmlns:xsf="http://schemas.microsoft.com/office/infopath/2003/solutionDefinition" xmlns:xsf2="http://schemas.microsoft.com/office/infopath/2006/solutionDefinition/extensions" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xdUtil="http://schemas.microsoft.com/office/infopath/2003/xslt/Util" xmlns:xdXDocument="http://schemas.microsoft.com/office/infopath/2003/xslt/xDocument" xmlns:xdMath="http://schemas.microsoft.com/office/infopath/2003/xslt/Math" xmlns:xdDate="http://schemas.microsoft.com/office/infopath/2003/xslt/Date" xmlns:xdExtension="http://schemas.microsoft.com/office/infopath/2003/xslt/extension" xmlns:xdEnvironment="http://schemas.microsoft.com/office/infopath/2006/xslt/environment" xmlns:xdUser="http://schemas.microsoft.com/office/infopath/2006/xslt/User" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-06-30T14:56:08" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields" xmlns:tns="http://rjbtech.com/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

  • 08-25-2009 01:43 PM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

     Do you have any experience working with the XmlDocument/XmlNode classes?  Can you show us the code you have so far so I can fill you in on the necessary missing steps?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-25-2009 04:52 PM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

    Below is what I have so far. I want to replace "FormName" in the xsf:xDocumentClass name="..." attribute with "Prefix-FormName", write it to manifest.xsf and save it.

                    XmlDocument xmlDoc = new XmlDocument();
                    XmlTextReader xmlReader = new XmlTextReader(@"C:\manifest.xsf");
                    while (xmlReader.Read())
                    {
                        if (xmlReader.NodeType.Equals(XmlNodeType.Element) && xmlReader.Name.Equals("xsf:xDocumentClass"))
                        {
                            while (xmlReader.MoveToNextAttribute())
                            {
                                if(xmlReader.Value.Contains("FormName"))
                                {
                                    string urnAttribute = xmlReader.Value;
                                    urnAttribute.Replace("FormName", "Prefix-FormName");
                                }
                            }
                        }
                    }

  • 08-25-2009 05:44 PM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

     This should be all you need:

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(@"C:\manifest.xsf");

                XmlAttribute nameAttr = xmlDoc.DocumentElement.Attributes["name"];
                if (nameAttr != null && nameAttr.Value.Contains("FormName")  &&
                    !nameAttr.Value.Contains("Prefix-FormName"))
                {
                    nameAttr.Value = nameAttr.Value.Replace("FormName", "Prefix-FormName");
                }

                xmlDoc.Save(@"C:\manifest.xsf");
     

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-25-2009 09:26 PM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

    This works great, thanks Jimmy.

    Now this is interesting... when I try the same method against template.xml in order to replace the name attribute value in 

    <?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:FormName:-myXSD-2008-06-30T14-56-08" solutionVersion="1.0.0.575" productVersion="12.0.0" PIVersion="1.0.0.0" ?>

    it is not able to find the attribute. The XmlDocument class must not be recognizing these as DocumentElements and I don't see any member of XmlDocument that would let me get at the name attribute in a <? ?> node. Is there a way?

  • 08-26-2009 05:29 AM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

     That's because they're not DocumentElements; they're processing instructions.  To get at a processing instruction, you'll need to do something like this:

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(@"C:\template.xml");

                XmlProcessingInstruction ipPi = xmlDoc.SelectSingleNode("processing-instruction()[local-name() = 'mso-infoPathSolution']")
                    as XmlProcessingInstruction;
                if (ipPi != null && ipPi.Value.Contains("CertFormPub")  &&
                    !ipPi.Value.Contains("Prefix-FormName"))
                {
                    ipPi.Value = ipPi.Value.Replace("CertFormPub", "Prefix-FormName");
                }


                xmlDoc.Save(@"C:\template.xml");

      There's no easy way to get at the attributes inside a processing instruction, so you're probably best off doing the string processing on the whole PI value.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-26-2009 09:30 AM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

    Wow, this is perfect. I owe you a drink when I visit Japan!

  • 09-12-2009 01:29 AM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

     Any one down this path remember to use "XMLDocument.PreserveWhitespace = True". gave me night mares, until I used this before modifying the manifest.xsf file.

    ---
    Deepak N Naidu
    "Giant Leap Starts With One Small Step"
    http://deepakn.info/blog
  • 09-23-2009 08:39 AM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

    When PreserveWhitespace is not set, the manifest file is saved in this format:

    <xsf:property name="namespace" type="string" value="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-29T15:31:35">
    </xsf:property>

    and I have errors because there are spaces within the opening and closing tags. It should look like:

    <xsf:property name="namespace" type="string" value="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-29T15:31:35"></xsf:property>

    But when I set PreserveWhitespace to true, the manifest file's xml is compressed into one line like:

    <xsf:fileProperties><xsf:property name="namespace" type="string" value="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-29T15:31:35"></xsf:property><xsf:property name="editability" type="string" value="full"></xsf:property><xsf:property name="rootElement" type="string" value="myFields"></xsf:property>

     This is causing errors as well.

     Is there any middle ground?

  • 09-25-2009 06:11 AM In reply to

    Re: Get Attribute of xsf:xDocumentClass Node in manifest.xsf

     What method are you using to do the changes. I am using this

                    nameSpaceManager.AddNamespace("xsf", gXsfNamespace2003);
                    nameSpaceManager.AddNamespace("xsf2", gXsfNamespace2007);

                    XPathNavigator nodePathToModify = manifestXML.CreateNavigator().SelectSingleNode(PathToModify, nameSpaceManager);
                    nodePathToModify.SetValue(ValueInxPath);

    hope this helps...Because in some of trials, I was getting the same result as it is doing with your xsf file.

     

    ---
    Deepak N Naidu
    "Giant Leap Starts With One Small Step"
    http://deepakn.info/blog
Page 1 of 2 (20 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.